avformat/dashdec: refine and fix code style of dash_read_header

move the temp variable to the top of the expression paragraph
rename the pls to rep(representation)
This commit is contained in:
Steven Liu 2019-07-04 16:11:47 +08:00
parent 43e0ddd33d
commit 6e988b75df
1 changed files with 32 additions and 35 deletions

View File

@ -2028,6 +2028,7 @@ static int copy_init_section(struct representation *rep_dest, struct representat
static int dash_read_header(AVFormatContext *s) static int dash_read_header(AVFormatContext *s)
{ {
DASHContext *c = s->priv_data; DASHContext *c = s->priv_data;
struct representation *rep;
int ret = 0; int ret = 0;
int stream_index = 0; int stream_index = 0;
int i; int i;
@ -2053,17 +2054,17 @@ static int dash_read_header(AVFormatContext *s)
/* Open the demuxer for video and audio components if available */ /* Open the demuxer for video and audio components if available */
for (i = 0; i < c->n_videos; i++) { for (i = 0; i < c->n_videos; i++) {
struct representation *cur_video = c->videos[i]; rep = c->videos[i];
if (i > 0 && c->is_init_section_common_video) { if (i > 0 && c->is_init_section_common_video) {
ret = copy_init_section(cur_video,c->videos[0]); ret = copy_init_section(rep, c->videos[0]);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
} }
ret = open_demux_for_component(s, cur_video); ret = open_demux_for_component(s, rep);
if (ret) if (ret)
goto fail; goto fail;
cur_video->stream_index = stream_index; rep->stream_index = stream_index;
++stream_index; ++stream_index;
} }
@ -2071,17 +2072,17 @@ static int dash_read_header(AVFormatContext *s)
c->is_init_section_common_audio = is_common_init_section_exist(c->audios, c->n_audios); c->is_init_section_common_audio = is_common_init_section_exist(c->audios, c->n_audios);
for (i = 0; i < c->n_audios; i++) { for (i = 0; i < c->n_audios; i++) {
struct representation *cur_audio = c->audios[i]; rep = c->audios[i];
if (i > 0 && c->is_init_section_common_audio) { if (i > 0 && c->is_init_section_common_audio) {
ret = copy_init_section(cur_audio,c->audios[0]); ret = copy_init_section(rep, c->audios[0]);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
} }
ret = open_demux_for_component(s, cur_audio); ret = open_demux_for_component(s, rep);
if (ret) if (ret)
goto fail; goto fail;
cur_audio->stream_index = stream_index; rep->stream_index = stream_index;
++stream_index; ++stream_index;
} }
@ -2089,21 +2090,20 @@ static int dash_read_header(AVFormatContext *s)
c->is_init_section_common_audio = is_common_init_section_exist(c->subtitles, c->n_subtitles); c->is_init_section_common_audio = is_common_init_section_exist(c->subtitles, c->n_subtitles);
for (i = 0; i < c->n_subtitles; i++) { for (i = 0; i < c->n_subtitles; i++) {
struct representation *cur_subtitle = c->subtitles[i]; rep = c->subtitles[i];
if (i > 0 && c->is_init_section_common_audio) { if (i > 0 && c->is_init_section_common_audio) {
ret = copy_init_section(cur_subtitle,c->subtitles[0]); ret = copy_init_section(rep, c->subtitles[0]);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
} }
ret = open_demux_for_component(s, cur_subtitle); ret = open_demux_for_component(s, rep);
if (ret) if (ret)
goto fail; goto fail;
cur_subtitle->stream_index = stream_index; rep->stream_index = stream_index;
++stream_index; ++stream_index;
} }
if (!stream_index) { if (!stream_index) {
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
@ -2118,33 +2118,30 @@ static int dash_read_header(AVFormatContext *s)
} }
for (i = 0; i < c->n_videos; i++) { for (i = 0; i < c->n_videos; i++) {
struct representation *pls = c->videos[i]; rep = c->videos[i];
av_program_add_stream_index(s, 0, rep->stream_index);
av_program_add_stream_index(s, 0, pls->stream_index); rep->assoc_stream = s->streams[rep->stream_index];
pls->assoc_stream = s->streams[pls->stream_index]; if (rep->bandwidth > 0)
if (pls->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0);
av_dict_set_int(&pls->assoc_stream->metadata, "variant_bitrate", pls->bandwidth, 0); if (rep->id[0])
if (pls->id[0]) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0);
av_dict_set(&pls->assoc_stream->metadata, "id", pls->id, 0);
} }
for (i = 0; i < c->n_audios; i++) { for (i = 0; i < c->n_audios; i++) {
struct representation *pls = c->audios[i]; rep = c->audios[i];
av_program_add_stream_index(s, 0, rep->stream_index);
av_program_add_stream_index(s, 0, pls->stream_index); rep->assoc_stream = s->streams[rep->stream_index];
pls->assoc_stream = s->streams[pls->stream_index]; if (rep->bandwidth > 0)
if (pls->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0);
av_dict_set_int(&pls->assoc_stream->metadata, "variant_bitrate", pls->bandwidth, 0); if (rep->id[0])
if (pls->id[0]) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0);
av_dict_set(&pls->assoc_stream->metadata, "id", pls->id, 0);
} }
for (i = 0; i < c->n_subtitles; i++) { for (i = 0; i < c->n_subtitles; i++) {
struct representation *pls = c->subtitles[i]; rep = c->subtitles[i];
av_program_add_stream_index(s, 0, pls->stream_index); av_program_add_stream_index(s, 0, rep->stream_index);
pls->assoc_stream = s->streams[pls->stream_index]; rep->assoc_stream = s->streams[rep->stream_index];
if (pls->id[0]) if (rep->id[0])
av_dict_set(&pls->assoc_stream->metadata, "id", pls->id, 0); av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0);
} }
} }
return 0; return 0;