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

Improve code style #85

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
46 changes: 23 additions & 23 deletions libavformat/imf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,36 @@ typedef uint8_t FFIMFUUID[16];
* IMF Composition Playlist Base Resource
*/
typedef struct FFIMFBaseResource {
AVRational edit_rate; /**< BaseResourceType/EditRate */
uint32_t entry_point; /**< BaseResourceType/EntryPoint */
uint32_t duration; /**< BaseResourceType/Duration */
uint32_t repeat_count; /**< BaseResourceType/RepeatCount */
AVRational edit_rate; /**< BaseResourceType/EditRate */
uint32_t entry_point; /**< BaseResourceType/EntryPoint */
uint32_t duration; /**< BaseResourceType/Duration */
uint32_t repeat_count; /**< BaseResourceType/RepeatCount */
} FFIMFBaseResource;

/**
* IMF Composition Playlist Track File Resource
*/
typedef struct FFIMFTrackFileResource {
FFIMFBaseResource base;
FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
} FFIMFTrackFileResource;

/**
* IMF Marker
*/
typedef struct FFIMFMarker {
xmlChar *label_utf8; /**< Marker/Label */
xmlChar *scope_utf8; /**< Marker/Label/\@scope */
uint32_t offset; /**< Marker/Offset */
xmlChar *label_utf8; /**< Marker/Label */
xmlChar *scope_utf8; /**< Marker/Label/\@scope */
uint32_t offset; /**< Marker/Offset */
} FFIMFMarker;

/**
* IMF Composition Playlist Marker Resource
*/
typedef struct FFIMFMarkerResource {
FFIMFBaseResource base;
uint32_t marker_count; /**< Number of Marker elements */
FFIMFMarker *markers; /**< Marker elements */
uint32_t marker_count; /**< Number of Marker elements */
FFIMFMarker *markers; /**< Marker elements */
} FFIMFMarkerResource;

/**
Expand All @@ -116,32 +116,32 @@ typedef struct FFIMFBaseVirtualTrack {
* IMF Composition Playlist Virtual Track that consists of Track File Resources
*/
typedef struct FFIMFTrackFileVirtualTrack {
FFIMFBaseVirtualTrack base;
uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */
unsigned int resources_alloc_sz; /**< Size of the resources buffer */
FFIMFBaseVirtualTrack base;
uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */
unsigned int resources_alloc_sz; /**< Size of the resources buffer */
} FFIMFTrackFileVirtualTrack;

/**
* IMF Composition Playlist Virtual Track that consists of Marker Resources
*/
typedef struct FFIMFMarkerVirtualTrack {
FFIMFBaseVirtualTrack base;
uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
} FFIMFMarkerVirtualTrack;

/**
* IMF Composition Playlist
*/
typedef struct FFIMFCPL {
FFIMFUUID id_uuid; /**< CompositionPlaylist/Id element */
xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */
AVRational edit_rate; /**< CompositionPlaylist/EditRate element */
FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */
FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */
uint32_t main_audio_track_count; /**< Number of Main Audio Virtual Tracks */
FFIMFTrackFileVirtualTrack *main_audio_tracks; /**< Main Audio Virtual Tracks */
FFIMFUUID id_uuid; /**< CompositionPlaylist/Id element */
xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */
AVRational edit_rate; /**< CompositionPlaylist/EditRate element */
FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */
FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */
uint32_t main_audio_track_count; /**< Number of Main Audio Virtual Tracks */
FFIMFTrackFileVirtualTrack *main_audio_tracks; /**< Main Audio Virtual Tracks */
} FFIMFCPL;

/**
Expand Down
78 changes: 37 additions & 41 deletions libavformat/imf_cpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,10 @@ int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16])
int ret = 0;

element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
scanf_ret = sscanf(element_text,
FF_IMF_UUID_FORMAT,
&uuid[0],
&uuid[1],
&uuid[2],
&uuid[3],
&uuid[4],
&uuid[5],
&uuid[6],
&uuid[7],
&uuid[8],
&uuid[9],
&uuid[10],
&uuid[11],
&uuid[12],
&uuid[13],
&uuid[14],
scanf_ret = sscanf(element_text, FF_IMF_UUID_FORMAT,
&uuid[ 0], &uuid[ 1], &uuid[ 2], &uuid[ 3], &uuid[ 4],
&uuid[ 5], &uuid[ 6], &uuid[ 7], &uuid[ 8], &uuid[ 9],
&uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
&uuid[15]);
if (scanf_ret != 16) {
av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
Expand Down Expand Up @@ -190,9 +177,8 @@ static int fill_content_title(xmlNodePtr cpl_element, FFIMFCPL *cpl)
av_log(NULL, AV_LOG_ERROR, "ContentTitle element not found in the IMF CPL\n");
return AVERROR_INVALIDDATA;
}
cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc,
element->xmlChildrenNode,
1);

cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc, element->xmlChildrenNode, 1);

return 0;
}
Expand Down Expand Up @@ -231,6 +217,7 @@ static int fill_marker(xmlNodePtr marker_elem, FFIMFMarker *marker)
av_log(NULL, AV_LOG_ERROR, "Offset element not found in a Marker\n");
return AVERROR_INVALIDDATA;
}

if ((ret = ff_imf_xml_read_uint32(element, &marker->offset)))
return ret;

Expand All @@ -239,13 +226,14 @@ static int fill_marker(xmlNodePtr marker_elem, FFIMFMarker *marker)
av_log(NULL, AV_LOG_ERROR, "Label element not found in a Marker\n");
return AVERROR_INVALIDDATA;
}

if (!(marker->label_utf8 = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1))) {
av_log(NULL, AV_LOG_ERROR, "Empty Label element found in a Marker\n");
return AVERROR_INVALIDDATA;
}

if (!(marker->scope_utf8 = xmlGetNoNsProp(element, "scope"))) {
marker->scope_utf8
= xmlCharStrdup("http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers");
marker->scope_utf8 = xmlCharStrdup("http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers");
if (!marker->scope_utf8) {
xmlFree(marker->label_utf8);
return AVERROR(ENOMEM);
Expand Down Expand Up @@ -283,6 +271,7 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou
av_log(NULL, AV_LOG_ERROR, "IntrinsicDuration element missing from Resource\n");
return AVERROR_INVALIDDATA;
}

if ((ret = ff_imf_xml_read_uint32(element, &resource->duration))) {
av_log(NULL, AV_LOG_ERROR, "Invalid IntrinsicDuration element found in a Resource\n");
return ret;
Expand All @@ -305,8 +294,7 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou
}

static int fill_trackfile_resource(xmlNodePtr tf_resource_elem,
FFIMFTrackFileResource *tf_resource,
FFIMFCPL *cpl)
FFIMFTrackFileResource *tf_resource, FFIMFCPL *cpl)
{
xmlNodePtr element = NULL;
int ret = 0;
Expand All @@ -329,8 +317,7 @@ static int fill_trackfile_resource(xmlNodePtr tf_resource_elem,
}

static int fill_marker_resource(xmlNodePtr marker_resource_elem,
FFIMFMarkerResource *marker_resource,
FFIMFCPL *cpl)
FFIMFMarkerResource *marker_resource, FFIMFCPL *cpl)
{
xmlNodePtr element = NULL;
int ret = 0;
Expand All @@ -354,8 +341,7 @@ static int fill_marker_resource(xmlNodePtr marker_resource_elem,
marker_resource->markers = tmp;

imf_marker_init(&marker_resource->markers[marker_resource->marker_count]);
ret = fill_marker(element,
&marker_resource->markers[marker_resource->marker_count]);
ret = fill_marker(element, &marker_resource->markers[marker_resource->marker_count]);
marker_resource->marker_count++;
if (ret)
return ret;
Expand All @@ -382,12 +368,13 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
av_log(NULL, AV_LOG_ERROR, "TrackId element missing from Sequence\n");
return AVERROR_INVALIDDATA;
}

if (ff_imf_xml_read_uuid(track_id_elem, uuid)) {
av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in Sequence\n");
return AVERROR_INVALIDDATA;
}
av_log(NULL,
AV_LOG_DEBUG,

av_log(NULL, AV_LOG_DEBUG,
"Processing IMF CPL Marker Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n",
UID_ARG(uuid));

Expand All @@ -396,6 +383,7 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
cpl->main_markers_track = av_malloc(sizeof(FFIMFMarkerVirtualTrack));
if (!cpl->main_markers_track)
return AVERROR(ENOMEM);

imf_marker_virtual_track_init(cpl->main_markers_track);
memcpy(cpl->main_markers_track->base.id_uuid, uuid, sizeof(uuid));

Expand All @@ -413,6 +401,7 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
if (resource_elem_count > UINT32_MAX
|| cpl->main_markers_track->resource_count > UINT32_MAX - resource_elem_count)
return AVERROR(ENOMEM);

tmp = av_realloc_array(cpl->main_markers_track->resources,
cpl->main_markers_track->resource_count + resource_elem_count,
sizeof(FFIMFMarkerResource));
Expand Down Expand Up @@ -470,10 +459,12 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp
av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");
return AVERROR_INVALIDDATA;
}

if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {
av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");
return ret;
}

av_log(NULL,
AV_LOG_DEBUG,
"Processing IMF CPL Audio Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n",
Expand Down Expand Up @@ -513,8 +504,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp
if (resource_elem_count > UINT32_MAX
|| vt->resource_count > UINT32_MAX - resource_elem_count)
return AVERROR(ENOMEM);
tmp = av_fast_realloc(vt->resources,
&vt->resources_alloc_sz,
tmp = av_fast_realloc(vt->resources, &vt->resources_alloc_sz,
(vt->resource_count + resource_elem_count)
* sizeof(FFIMFTrackFileResource));
if (!tmp) {
Expand All @@ -526,9 +516,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp
resource_elem = xmlFirstElementChild(resource_list_elem);
while (resource_elem) {
imf_trackfile_resource_init(&vt->resources[vt->resource_count]);
ret = fill_trackfile_resource(resource_elem,
&vt->resources[vt->resource_count],
cpl);
ret = fill_trackfile_resource(resource_elem, &vt->resources[vt->resource_count], cpl);
vt->resource_count++;
if (ret) {
av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");
Expand Down Expand Up @@ -562,6 +550,7 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL
av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");
return AVERROR_INVALIDDATA;
}

if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {
av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");
return ret;
Expand All @@ -579,8 +568,8 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL
av_log(NULL, AV_LOG_ERROR, "Multiple MainImage virtual tracks found\n");
return AVERROR_INVALIDDATA;
}
av_log(NULL,
AV_LOG_DEBUG,

av_log(NULL, AV_LOG_DEBUG,
"Processing IMF CPL Main Image Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n",
UID_ARG(uuid));

Expand All @@ -595,6 +584,7 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL
|| (cpl->main_image_2d_track->resource_count + resource_elem_count)
> INT_MAX / sizeof(FFIMFTrackFileResource))
return AVERROR(ENOMEM);

tmp = av_fast_realloc(cpl->main_image_2d_track->resources,
&cpl->main_image_2d_track->resources_alloc_sz,
(cpl->main_image_2d_track->resource_count + resource_elem_count)
Expand Down Expand Up @@ -658,8 +648,7 @@ static int fill_virtual_tracks(xmlNodePtr cpl_element, FFIMFCPL *cpl)
ret = push_main_audio_sequence(sequence_elem, cpl);

else
av_log(NULL,
AV_LOG_INFO,
av_log(NULL, AV_LOG_INFO,
"The following Sequence is not supported and is ignored: %s\n",
sequence_elem->name);

Expand Down Expand Up @@ -715,6 +704,7 @@ static void imf_marker_free(FFIMFMarker *marker)
{
if (!marker)
return;

xmlFree(marker->label_utf8);
xmlFree(marker->scope_utf8);
}
Expand All @@ -723,24 +713,29 @@ static void imf_marker_resource_free(FFIMFMarkerResource *rsrc)
{
if (!rsrc)
return;

for (uint32_t i = 0; i < rsrc->marker_count; i++)
imf_marker_free(&rsrc->markers[i]);

av_freep(&rsrc->markers);
}

static void imf_marker_virtual_track_free(FFIMFMarkerVirtualTrack *vt)
{
if (!vt)
return;

for (uint32_t i = 0; i < vt->resource_count; i++)
imf_marker_resource_free(&vt->resources[i]);

av_freep(&vt->resources);
}

static void imf_trackfile_virtual_track_free(FFIMFTrackFileVirtualTrack *vt)
{
if (!vt)
return;

av_freep(&vt->resources);
}

Expand All @@ -759,9 +754,9 @@ FFIMFCPL *ff_imf_cpl_alloc(void)
{
FFIMFCPL *cpl;

cpl = av_malloc(sizeof(FFIMFCPL));
if (!cpl)
if (!(cpl = av_malloc(sizeof(FFIMFCPL))))
return NULL;

imf_cpl_init(cpl);
return cpl;
}
Expand Down Expand Up @@ -803,6 +798,7 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)
filesize = filesize > 0 ? filesize : 8192;
av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED);
ret = avio_read_to_bprint(in, &buf, UINT_MAX - 1);

if (ret < 0 || !avio_feof(in) || buf.len == 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot read IMF CPL\n");
if (ret == 0)
Expand Down
Loading