Skip to content

Commit

Permalink
utf-8 character
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Apr 25, 2020
1 parent fca313e commit e5d6182
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 144 deletions.
29 changes: 17 additions & 12 deletions libdash/libdash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 46C5B2232183EAAD00419E57;
productRefGroup = 46C5B22D2183EAAD00419E57 /* Products */;
Expand Down Expand Up @@ -185,6 +186,12 @@
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
USER_HEADER_SEARCH_PATHS = (
.,
./include,
../libmov/include,
../../sdk/include,
);
};
name = Debug;
};
Expand Down Expand Up @@ -237,6 +244,12 @@
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
USER_HEADER_SEARCH_PATHS = (
.,
./include,
../libmov/include,
../../sdk/include,
);
};
name = Release;
};
Expand All @@ -245,14 +258,10 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = (
.,
"$(SRCROOT)/include",
"$(SRCROOT)/../libmov/include",
"$(SRCROOT)/../../sdk/include",
);
USER_HEADER_SEARCH_PATHS = "$(inherited)";
};
name = Debug;
};
Expand All @@ -261,14 +270,10 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = (
.,
"$(SRCROOT)/include",
"$(SRCROOT)/../libmov/include",
"$(SRCROOT)/../../sdk/include",
);
USER_HEADER_SEARCH_PATHS = "$(inherited)";
};
name = Release;
};
Expand Down
2 changes: 2 additions & 0 deletions libdash/src/dash-mpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ static int dash_adaptation_set_segment(struct dash_mpd_t* mpd, struct dash_adapt
return r;

seg = (struct dash_segment_t*)calloc(1, sizeof(*seg));
if(!seg)
return -1; // ENOMEM
seg->timestamp = track->dts;
seg->duration = track->dts_last - track->dts;

Expand Down
7 changes: 5 additions & 2 deletions libdash/test/dash-dynamic-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ static int dash_mpd_onsegment(void* param, int /*track*/, const void* data, size
{
app_log(LOG_DEBUG, "dash_mpd_onsegment %s\n", name);
FILE* fp = fopen(name, "wb");
fwrite(data, 1, bytes, fp);
fclose(fp);
if(fp)
{
fwrite(data, 1, bytes, fp);
fclose(fp);
}

dash_playlist_t* dash = (dash_playlist_t*)param;
if(!strendswith(name, "-init.m4v") && !strendswith(name, "-init.m4a"))
Expand Down
5 changes: 5 additions & 0 deletions libflv/include/flv-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ int flv_data_tag_header_read(const uint8_t* buf, int len);
/// @return >=0-header length in byte, <0-error
int flv_data_tag_header_write(uint8_t* buf, int len);


/// Read/Write FLV previous tag size
int flv_tag_size_read(const uint8_t* buf, int len, uint32_t* size);
int flv_tag_size_write(uint8_t* buf, int len, uint32_t size);

#if defined(__cplusplus)
}
#endif
Expand Down
24 changes: 14 additions & 10 deletions libflv/libflv.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
USER_HEADER_SEARCH_PATHS = (
.,
./include,
../../sdk/include,
);
};
name = Debug;
};
Expand Down Expand Up @@ -306,6 +311,11 @@
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
USER_HEADER_SEARCH_PATHS = (
.,
./include,
../../sdk/include,
);
};
name = Release;
};
Expand All @@ -314,13 +324,10 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = (
.,
"$(SRCROOT)/include",
"$(SRCROOT)/../../sdk/include",
);
USER_HEADER_SEARCH_PATHS = "$(inherited)";
};
name = Debug;
};
Expand All @@ -329,13 +336,10 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = (
.,
"$(SRCROOT)/include",
"$(SRCROOT)/../../sdk/include",
);
USER_HEADER_SEARCH_PATHS = "$(inherited)";
};
name = Release;
};
Expand Down
16 changes: 16 additions & 0 deletions libflv/source/flv-header.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,19 @@ int flv_data_tag_header_write(uint8_t* buf, int len)
(void)len;
return 0;
}

int flv_tag_size_read(const uint8_t* buf, int len, uint32_t* size)
{
if(len < 4)
return -1;
*size = be_read_uint32(buf);
return 4;
}

int flv_tag_size_write(uint8_t* buf, int len, uint32_t size)
{
if(len < 4)
return -1;
be_write_uint32(buf, size);
return 4;
}
19 changes: 9 additions & 10 deletions libflv/source/flv-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ struct flv_reader_t
void* param;
};

static uint32_t be_read_uint32(const uint8_t* ptr)
{
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
}

static int flv_read_header(struct flv_reader_t* flv)
{
uint32_t sz;
uint8_t data[FLV_HEADER_SIZE];
struct flv_header_t h;
int n;
Expand All @@ -41,8 +37,9 @@ static int flv_read_header(struct flv_reader_t* flv)
if (4 != flv->read(flv->param, data, 4))
return -1;

assert(be_read_uint32(data) == 0);
return be_read_uint32(data) == 0 ? 0 : -1;
flv_tag_size_read(data, 4, &sz);
assert(0 == sz);
return 0 == sz ? 0 : -1;
}

static int file_read(void* param, void* buf, int len)
Expand Down Expand Up @@ -101,6 +98,7 @@ void flv_reader_destroy(void* p)

int flv_reader_read(void* p, int* tagtype, uint32_t* timestamp, void* buffer, size_t bytes)
{
uint32_t sz;
uint8_t header[FLV_TAG_HEADER_SIZE];
struct flv_tag_header_t tag;
struct flv_reader_t* flv;
Expand All @@ -125,7 +123,8 @@ int flv_reader_read(void* p, int* tagtype, uint32_t* timestamp, void* buffer, si

*tagtype = tag.type;
*timestamp = tag.timestamp;
assert(0 == tag.streamId); // StreamID Always 0
assert(be_read_uint32(header) == tag.size + FLV_TAG_HEADER_SIZE);
return (be_read_uint32(header) == tag.size + FLV_TAG_HEADER_SIZE) ? tag.size : -1;
flv_tag_size_read(header, 4, &sz);
assert(0 == tag.streamId); // StreamID Always 0
assert(sz == tag.size + FLV_TAG_HEADER_SIZE);
return (sz == tag.size + FLV_TAG_HEADER_SIZE) ? tag.size : -1;
}
12 changes: 2 additions & 10 deletions libflv/source/flv-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ struct flv_writer_t
void* param;
};

static void be_write_uint32(uint8_t* ptr, uint32_t val)
{
ptr[0] = (uint8_t)((val >> 24) & 0xFF);
ptr[1] = (uint8_t)((val >> 16) & 0xFF);
ptr[2] = (uint8_t)((val >> 8) & 0xFF);
ptr[3] = (uint8_t)(val & 0xFF);
}

static int flv_write_header(struct flv_writer_t* flv)
{
uint8_t header[FLV_HEADER_SIZE + 4];
flv_header_write(1, 1, header, FLV_HEADER_SIZE);
be_write_uint32(header + FLV_HEADER_SIZE, 0); // PreviousTagSize0(Always 0)
flv_tag_size_write(header + FLV_HEADER_SIZE, 4, 0); // PreviousTagSize0(Always 0)
return sizeof(header) == flv->write(flv->param, header, sizeof(header)) ? 0 : -1;
}

Expand Down Expand Up @@ -115,7 +107,7 @@ int flv_writer_input(void* p, int type, const void* data, size_t bytes, uint32_t
tag.type = (uint8_t)type;
tag.timestamp = timestamp;
flv_tag_header_write(&tag, buf, FLV_TAG_HEADER_SIZE);
be_write_uint32(buf + FLV_TAG_HEADER_SIZE, (uint32_t)bytes + FLV_TAG_HEADER_SIZE);
flv_tag_size_write(buf + FLV_TAG_HEADER_SIZE, 4, (uint32_t)bytes + FLV_TAG_HEADER_SIZE);

if(FLV_TAG_HEADER_SIZE != flv->write(flv->param, buf, FLV_TAG_HEADER_SIZE) // FLV Tag Header
|| bytes != (size_t)flv->write(flv->param, data, (int)bytes)
Expand Down
14 changes: 7 additions & 7 deletions libflv/source/mpeg4-avc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = ¡®111111¡¯b;
bit(6) reserved = '111111'b;
unsigned int(2) lengthSizeMinusOne;
bit(3) reserved = ¡®111¡¯b;
bit(3) reserved = '111'b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSets; i++) {
Expand All @@ -30,11 +30,11 @@ aligned(8) class AVCDecoderConfigurationRecord {
if( profile_idc == 100 || profile_idc == 110 ||
profile_idc == 122 || profile_idc == 144 )
{
bit(6) reserved = ¡®111111¡¯b;
bit(6) reserved = '111111'b;
unsigned int(2) chroma_format;
bit(5) reserved = ¡®11111¡¯b;
bit(5) reserved = '11111'b;
unsigned int(3) bit_depth_luma_minus8;
bit(5) reserved = ¡®11111¡¯b;
bit(5) reserved = '11111'b;
unsigned int(3) bit_depth_chroma_minus8;
unsigned int(8) numOfSequenceParameterSetExt;
for (i=0; i< numOfSequenceParameterSetExt; i++) {
Expand Down Expand Up @@ -71,7 +71,7 @@ int mpeg4_avc_decoder_configuration_record_load(const uint8_t* data, size_t byte
for (i = 0; i < avc->nb_sps && j + 2 < bytes; ++i)
{
len = (data[j] << 8) | data[j + 1];
if (len + j + 2 >= bytes || p + len > end)
if (j + 2 + len >= bytes || p + len > end)
{
assert(0);
return -1;
Expand All @@ -94,7 +94,7 @@ int mpeg4_avc_decoder_configuration_record_load(const uint8_t* data, size_t byte
for (i = 0; i < avc->nb_pps && j + 2 < bytes; i++)
{
len = (data[j] << 8) | data[j + 1];
if (len + j + 2 > bytes || p + len > end)
if (j + 2 + len > bytes || p + len > end)
{
assert(0);
return -1;
Expand Down
10 changes: 5 additions & 5 deletions libflv/source/mpeg4-hevc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ aligned(8) class HEVCDecoderConfigurationRecord {
unsigned int(32) general_profile_compatibility_flags;
unsigned int(48) general_constraint_indicator_flags;
unsigned int(8) general_level_idc;
bit(4) reserved = ¡®1111¡¯b;
bit(4) reserved = '1111'b;
unsigned int(12) min_spatial_segmentation_idc;
bit(6) reserved = ¡®111111¡¯b;
bit(6) reserved = '111111'b;
unsigned int(2) parallelismType;
bit(6) reserved = ¡®111111¡¯b;
bit(6) reserved = '111111'b;
unsigned int(2) chromaFormat;
bit(5) reserved = ¡®11111¡¯b;
bit(5) reserved = '11111'b;
unsigned int(3) bitDepthLumaMinus8;
bit(5) reserved = ¡®11111¡¯b;
bit(5) reserved = '11111'b;
unsigned int(3) bitDepthChromaMinus8;
bit(16) avgFrameRate;
bit(2) constantFrameRate;
Expand Down
14 changes: 10 additions & 4 deletions libhls/demo/hls-segmenter-flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ static int hls_handler(void* m3u8, const void* data, size_t bytes, int64_t pts,
hls_m3u8_add((hls_m3u8_t*)m3u8, name, pts, duration, discontinue);

FILE* fp = fopen(name, "wb");
fwrite(data, 1, bytes, fp);
fclose(fp);
if(fp)
{
fwrite(data, 1, bytes, fp);
fclose(fp);
}

return 0;
}
Expand Down Expand Up @@ -71,8 +74,11 @@ void hls_segmenter_flv(const char* file)
hls_media_input(hls, STREAM_VIDEO_H264, NULL, 0, 0, 0, 0);
hls_m3u8_playlist(m3u, 1, data, sizeof(data));
FILE* fp = fopen("playlist.m3u8", "wb");
fwrite(data, 1, strlen(data), fp);
fclose(fp);
if(fp)
{
fwrite(data, 1, strlen(data), fp);
fclose(fp);
}

flv_demuxer_destroy(demuxer);
flv_reader_destroy(flv);
Expand Down
Loading

0 comments on commit e5d6182

Please sign in to comment.