Skip to content

Commit

Permalink
change: merge common codec extradata reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Oct 14, 2023
1 parent 8ee4b38 commit 7d22996
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 129 deletions.
3 changes: 0 additions & 3 deletions libmov/libmov.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\fmp4-reader.c" />
<ClCompile Include="source\mov-av1.c" />
<ClCompile Include="source\mov-avc1.c" />
<ClCompile Include="source\mov-dinf.c" />
<ClCompile Include="source\mov-elst.c" />
<ClCompile Include="source\fmp4-writer.c" />
<ClCompile Include="source\mov-ftyp.c" />
<ClCompile Include="source\mov-hdlr.c" />
<ClCompile Include="source\mov-hdr.c" />
<ClCompile Include="source\mov-hvcc.c" />
<ClCompile Include="source\mov-udta.c" />
<ClCompile Include="source\mov-iods.c" />
<ClCompile Include="source\mov-leva.c" />
Expand Down Expand Up @@ -70,7 +68,6 @@
<ClCompile Include="source\mov-trun.c" />
<ClCompile Include="source\mov-tx3g.c" />
<ClCompile Include="source\mov-vpcc.c" />
<ClCompile Include="source\mov-vvc.c" />
<ClCompile Include="source\mov-writer.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
Expand Down
9 changes: 0 additions & 9 deletions libmov/libmov.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@
<ClCompile Include="source\mov-avc1.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\mov-hvcc.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\mov-tag.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -152,9 +149,6 @@
<ClCompile Include="source\mov-opus.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\mov-av1.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\mov-hdr.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -167,8 +161,5 @@
<ClCompile Include="source\fmp4-reader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\mov-vvc.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
34 changes: 0 additions & 34 deletions libmov/source/mov-av1.c

This file was deleted.

49 changes: 46 additions & 3 deletions libmov/source/mov-avc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <stdlib.h>
#include <errno.h>

// extra_data: ISO/IEC 14496-15 AVCDecoderConfigurationRecord

int mov_read_avcc(struct mov_t* mov, const struct mov_box_t* box)
int mov_read_extra(struct mov_t* mov, const struct mov_box_t* box)
{
struct mov_track_t* track = mov->track;
struct mov_sample_entry_t* entry = track->stsd.current;
Expand All @@ -21,6 +19,7 @@ int mov_read_avcc(struct mov_t* mov, const struct mov_box_t* box)
return mov_buffer_error(&mov->io);
}

// extra_data: ISO/IEC 14496-15 AVCDecoderConfigurationRecord
size_t mov_write_avcc(const struct mov_t* mov)
{
const struct mov_track_t* track = mov->track;
Expand All @@ -31,3 +30,47 @@ size_t mov_write_avcc(const struct mov_t* mov)
mov_buffer_write(&mov->io, entry->extra_data, entry->extra_data_size);
return entry->extra_data_size + 8;
}

// extra_data: ISO/IEC 14496-15:2017 HEVCDecoderConfigurationRecord
size_t mov_write_hvcc(const struct mov_t* mov)
{
const struct mov_track_t* track = mov->track;
const struct mov_sample_entry_t* entry = track->stsd.current;
mov_buffer_w32(&mov->io, entry->extra_data_size + 8); /* size */
mov_buffer_write(&mov->io, "hvcC", 4);
if (entry->extra_data_size > 0)
mov_buffer_write(&mov->io, entry->extra_data, entry->extra_data_size);
return entry->extra_data_size + 8;
}

// https://aomediacodec.github.io/av1-isobmff
// extra data: AV1CodecConfigurationRecord

size_t mov_write_av1c(const struct mov_t* mov)
{
const struct mov_track_t* track = mov->track;
const struct mov_sample_entry_t* entry = track->stsd.current;
mov_buffer_w32(&mov->io, entry->extra_data_size + 8); /* size */
mov_buffer_write(&mov->io, "av1C", 4);
if (entry->extra_data_size > 0)
mov_buffer_write(&mov->io, entry->extra_data, entry->extra_data_size);
return entry->extra_data_size + 8;
}


// extra_data: ISO/IEC 14496-15 AVCDecoderConfigurationRecord
/*
class VvcConfigurationBox extends FullBox('vvcC',version=0,flags) {
VvcDecoderConfigurationRecord() VvcConfig;
}
*/
size_t mov_write_vvcc(const struct mov_t* mov)
{
const struct mov_track_t* track = mov->track;
const struct mov_sample_entry_t* entry = track->stsd.current;
mov_buffer_w32(&mov->io, entry->extra_data_size + 8); /* size */
mov_buffer_write(&mov->io, "vvcC", 4);
if (entry->extra_data_size > 0)
mov_buffer_write(&mov->io, entry->extra_data, entry->extra_data_size);
return entry->extra_data_size + 8;
}
33 changes: 0 additions & 33 deletions libmov/source/mov-hvcc.c

This file was deleted.

5 changes: 1 addition & 4 deletions libmov/source/mov-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ int mov_read_stts(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_ctts(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_cslg(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_stss(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_avcc(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_hvcc(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_vvcc(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_av1c(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_extra(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_vpcc(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_tx3g(struct mov_t* mov, const struct mov_box_t* box);
int mov_read_trex(struct mov_t* mov, const struct mov_box_t* box);
Expand Down
7 changes: 4 additions & 3 deletions libmov/source/mov-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ static int mov_read_default(struct mov_t* mov, const struct mov_box_t* box)
}

static struct mov_parse_t s_mov_parse_table[] = {
{ MOV_TAG('a', 'v', '1', 'C'), MOV_NULL, mov_read_av1c }, // av1-isobmff
{ MOV_TAG('a', 'v', 'c', 'C'), MOV_NULL, mov_read_avcc }, // ISO/IEC 14496-15:2010(E) avcC
{ MOV_TAG('a', 'v', '1', 'C'), MOV_NULL, mov_read_extra }, // av1-isobmff
{ MOV_TAG('a', 'v', 'c', 'C'), MOV_NULL, mov_read_extra }, // ISO/IEC 14496-15:2010(E) avcC
{ MOV_TAG('b', 't', 'r', 't'), MOV_NULL, mov_read_btrt }, // ISO/IEC 14496-15:2010(E) 5.3.4.1.1 Definition
{ MOV_TAG('c', 'o', '6', '4'), MOV_STBL, mov_read_stco },
{ MOV_TAG('C', 'o', 'L', 'L'), MOV_STBL, mov_read_coll },
Expand All @@ -223,7 +223,7 @@ static struct mov_parse_t s_mov_parse_table[] = {
{ MOV_TAG('g', 'm', 'i', 'n'), MOV_GMHD, mov_read_gmin }, // Apple QuickTime gmin
{ MOV_TAG('g', 'm', 'h', 'd'), MOV_MINF, mov_read_default }, // Apple QuickTime gmhd
{ MOV_TAG('h', 'd', 'l', 'r'), MOV_MDIA, mov_read_hdlr }, // Apple QuickTime minf also has hdlr
{ MOV_TAG('h', 'v', 'c', 'C'), MOV_NULL, mov_read_hvcc }, // ISO/IEC 14496-15:2014 hvcC
{ MOV_TAG('h', 'v', 'c', 'C'), MOV_NULL, mov_read_extra }, // ISO/IEC 14496-15:2014 hvcC
{ MOV_TAG('l', 'e', 'v', 'a'), MOV_MVEX, mov_read_leva },
{ MOV_TAG('m', 'd', 'a', 't'), MOV_ROOT, mov_read_mdat },
{ MOV_TAG('m', 'd', 'h', 'd'), MOV_MDIA, mov_read_mdhd },
Expand Down Expand Up @@ -265,6 +265,7 @@ static struct mov_parse_t s_mov_parse_table[] = {
{ MOV_TAG('u', 'u', 'i', 'd'), MOV_NULL, mov_read_uuid },
{ MOV_TAG('v', 'm', 'h', 'd'), MOV_MINF, mov_read_vmhd },
{ MOV_TAG('v', 'p', 'c', 'C'), MOV_NULL, mov_read_vpcc },
{ MOV_TAG('d', 'e', 'c', '3'), MOV_NULL, mov_read_extra }, // dolby EC-3

{ 0, 0, NULL } // last
};
Expand Down
2 changes: 1 addition & 1 deletion libmov/source/mov-stsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static int mov_read_video(struct mov_t* mov, struct mov_sample_entry_t* entry)
}

/*
class PixelAspectRatioBox extends Box(pasp?{
class PixelAspectRatioBox extends Box(pasp){
unsigned int(32) hSpacing;
unsigned int(32) vSpacing;
}
Expand Down
2 changes: 2 additions & 0 deletions libmov/source/mov-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static struct mov_object_tag s_tags[] = {
{ MOV_OBJECT_DTS, MOV_DTS },
{ MOV_OBJECT_VC1, MOV_VC1 },
{ MOV_OBJECT_DIRAC, MOV_DIRAC },

{ MOV_OBJECT_H265, MOV_TAG('d', 'v', 'h', '1') }, // Dolby Vision HEVC(H.265) dvhe
};

uint32_t mov_object_to_tag(uint8_t object)
Expand Down
38 changes: 0 additions & 38 deletions libmov/source/mov-vvc.c

This file was deleted.

2 changes: 1 addition & 1 deletion libmov/test/mov-reader-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void onread(void* flv, uint32_t track, const void* buffer, size_t bytes,
else if (it->second == "G711")
{
static int64_t t_pts, t_dts;
printf("[G711] pts: %s, dts: %s, diff: %03d/%03d, bytes: %u, text: %.*s\n", ftimestamp(pts, s_pts), ftimestamp(dts, s_dts), (int)(pts - t_pts), (int)(dts - t_dts), (unsigned int)bytes, (int)bytes-2, (const char*)buffer+2);
printf("[G711] pts: %s, dts: %s, diff: %03d/%03d, bytes: %u\n", ftimestamp(pts, s_pts), ftimestamp(dts, s_dts), (int)(pts - t_pts), (int)(dts - t_dts), (unsigned int)bytes);
t_pts = pts;
t_dts = dts;
}
Expand Down

0 comments on commit 7d22996

Please sign in to comment.