1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avformat/dashdec: Return early for unsupported representations

This allows to reduce the level of indentation for parsing the supported
representations (audio, video and subtitles). It also allows to avoid
some allocations and frees for unsupported representations.

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-09-19 12:08:00 +02:00
parent 622efc5c83
commit 0389625cea

View File

@ -852,9 +852,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
char *val = NULL;
xmlNodePtr baseurl_nodes[4];
xmlNodePtr representation_node = node;
char *rep_id_val = xmlGetProp(representation_node, "id");
char *rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
char *rep_id_val, *rep_bandwidth_val;
enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
// try get information from representation
@ -866,28 +864,29 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
// try get information from adaption set
if (type == AVMEDIA_TYPE_UNKNOWN)
type = get_content_type(adaptionset_node);
if (type == AVMEDIA_TYPE_UNKNOWN) {
if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO &&
type != AVMEDIA_TYPE_SUBTITLE) {
av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url);
} else if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
return 0;
}
// convert selected representation to our internal struct
rep = av_mallocz(sizeof(struct representation));
if (!rep) {
ret = AVERROR(ENOMEM);
goto end;
}
if (!rep)
return AVERROR(ENOMEM);
if (c->adaptionset_lang) {
rep->lang = av_strdup(c->adaptionset_lang);
if (!rep->lang) {
av_log(s, AV_LOG_ERROR, "alloc language memory failure\n");
av_freep(&rep);
ret = AVERROR(ENOMEM);
goto end;
return AVERROR(ENOMEM);
}
}
rep->parent = s;
representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate");
representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL");
representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList");
rep_id_val = xmlGetProp(representation_node, "id");
rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
baseurl_nodes[0] = mpd_baseurl_node;
baseurl_nodes[1] = period_baseurl_node;
@ -1054,10 +1053,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0;
strncpy(rep->id, rep_id_val ? rep_id_val : "", sizeof(rep->id));
rep->framerate = av_make_q(0, 0);
if (type == AVMEDIA_TYPE_VIDEO && rep_framerate_val) {
if (type == AVMEDIA_TYPE_VIDEO) {
char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
if (rep_framerate_val) {
ret = av_parse_video_rate(&rep->framerate, rep_framerate_val);
if (ret < 0)
av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val);
xmlFree(rep_framerate_val);
}
}
switch (type) {
@ -1073,15 +1076,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
}
if (ret < 0)
goto free;
}
end:
if (rep_id_val)
xmlFree(rep_id_val);
if (rep_bandwidth_val)
xmlFree(rep_bandwidth_val);
if (rep_framerate_val)
xmlFree(rep_framerate_val);
return ret;
enomem: