Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compiler error on Mac of missing endian.h #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ Compile the source code using this command (all one line):

g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil

## Installing on Mac

Download the source code from GitHub at https://github.com/ponchio/untrunc and unzip the source code.

cd untrunc-master

Install libav using homebrew

brew install libav

Build untrunc

g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil

## Installing on other operating system (Manual libav installation)

Expand Down
2 changes: 1 addition & 1 deletion atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <iostream>

#include <assert.h>
#include <endian.h>
#include "uendian.h"

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "file.h"
#include <string>
#include <endian.h>
#include "uendian.h"

using namespace std;

Expand Down
6 changes: 3 additions & 3 deletions track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <vector>
#include <string.h>
#include <assert.h>
#include <endian.h>
#include "uendian.h"

#define __STDC_LIMIT_MACROS 1
#define __STDC_CONSTANT_MACROS 1
Expand Down Expand Up @@ -201,7 +201,7 @@ bool Codec::matchSample(unsigned char *start, int maxlength) {

int Codec::getLength(unsigned char *start, int maxlength) {
if(name == "mp4a") {
AVFrame *frame = avcodec_alloc_frame();
AVFrame *frame = av_frame_alloc();
if(!frame)
throw string("Could not create AVFrame");
AVPacket avp;
Expand All @@ -217,7 +217,7 @@ int Codec::getLength(unsigned char *start, int maxlength) {
} else if(name == "mp4v") {

/* THIS DOES NOT SEEM TO WORK FOR SOME UNKNOWN REASON. IT JUST CONSUMES ALL BYTES.
* AVFrame *frame = avcodec_alloc_frame();
* AVFrame *frame = av_frame_alloc();
if(!frame)
throw string("Could not create AVFrame");
AVPacket avp;
Expand Down
33 changes: 33 additions & 0 deletions uendian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef UENDIAN_H__
#define UENDIAN_H__
#include <inttypes.h>
#include <string.h>

#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#include <endian.h>
#elif __FreeBSD__
#include <sys/endian.h>
#elif defined(__APPLE__) && defined(__MACH__)

#include <libkern/OSByteOrder.h>

#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)

#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)

#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)

#else
#error Couldn't find any appropriate endian.h
#endif // PLATFORMS

#endif // UENDIAN_H__