Browse code

Merge commit '1138eb5509d3db7f6d565cb45f137a786d22beb9'

* commit '1138eb5509d3db7f6d565cb45f137a786d22beb9':
vsrc_movie: convert to codecpar

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>

Derek Buitenhuis authored on 2016/04/11 22:42:30
Showing 1 changed files
... ...
@@ -46,6 +46,7 @@
46 46
 
47 47
 typedef struct MovieStream {
48 48
     AVStream *st;
49
+    AVCodecContext *codec_ctx;
49 50
     int done;
50 51
 } MovieStream;
51 52
 
... ...
@@ -133,11 +134,11 @@ static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
133 133
                          "did not match any stream");
134 134
         return NULL;
135 135
     }
136
-    if (found->codec->codec_type != AVMEDIA_TYPE_VIDEO &&
137
-        found->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
136
+    if (found->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
137
+        found->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
138 138
         av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
139 139
                "currently unsupported by libavfilter\n", spec,
140
-               av_get_media_type_string(found->codec->codec_type));
140
+               av_get_media_type_string(found->codecpar->codec_type));
141 141
         return NULL;
142 142
     }
143 143
     return found;
... ...
@@ -148,15 +149,23 @@ static int open_stream(void *log, MovieStream *st)
148 148
     AVCodec *codec;
149 149
     int ret;
150 150
 
151
-    codec = avcodec_find_decoder(st->st->codec->codec_id);
151
+    codec = avcodec_find_decoder(st->st->codecpar->codec_id);
152 152
     if (!codec) {
153 153
         av_log(log, AV_LOG_ERROR, "Failed to find any codec\n");
154 154
         return AVERROR(EINVAL);
155 155
     }
156 156
 
157
-    st->st->codec->refcounted_frames = 1;
157
+    st->codec_ctx = avcodec_alloc_context3(codec);
158
+    if (!st->codec_ctx)
159
+        return AVERROR(ENOMEM);
160
+
161
+    ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar);
162
+    if (ret < 0)
163
+        return ret;
164
+
165
+    st->codec_ctx->refcounted_frames = 1;
158 166
 
159
-    if ((ret = avcodec_open2(st->st->codec, codec, NULL)) < 0) {
167
+    if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
160 168
         av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
161 169
         return ret;
162 170
     }
... ...
@@ -166,24 +175,24 @@ static int open_stream(void *log, MovieStream *st)
166 166
 
167 167
 static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
168 168
 {
169
-    AVCodecContext *dec_ctx = st->st->codec;
169
+    AVCodecParameters *dec_par = st->st->codecpar;
170 170
     char buf[256];
171
-    int64_t chl = av_get_default_channel_layout(dec_ctx->channels);
171
+    int64_t chl = av_get_default_channel_layout(dec_par->channels);
172 172
 
173 173
     if (!chl) {
174 174
         av_log(log_ctx, AV_LOG_ERROR,
175 175
                "Channel layout is not set in stream %d, and could not "
176 176
                "be guessed from the number of channels (%d)\n",
177
-               st_index, dec_ctx->channels);
177
+               st_index, dec_par->channels);
178 178
         return AVERROR(EINVAL);
179 179
     }
180 180
 
181
-    av_get_channel_layout_string(buf, sizeof(buf), dec_ctx->channels, chl);
181
+    av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
182 182
     av_log(log_ctx, AV_LOG_WARNING,
183 183
            "Channel layout is not set in output stream %d, "
184 184
            "guessed channel layout is '%s'\n",
185 185
            st_index, buf);
186
-    dec_ctx->channel_layout = chl;
186
+    dec_par->channel_layout = chl;
187 187
     return 0;
188 188
 }
189 189
 
... ...
@@ -287,7 +296,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
287 287
         AVFilterPad pad = { 0 };
288 288
         movie->out_index[movie->st[i].st->index] = i;
289 289
         snprintf(name, sizeof(name), "out%d", i);
290
-        pad.type          = movie->st[i].st->codec->codec_type;
290
+        pad.type          = movie->st[i].st->codecpar->codec_type;
291 291
         pad.name          = av_strdup(name);
292 292
         if (!pad.name)
293 293
             return AVERROR(ENOMEM);
... ...
@@ -297,8 +306,8 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
297 297
         ret = open_stream(ctx, &movie->st[i]);
298 298
         if (ret < 0)
299 299
             return ret;
300
-        if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO &&
301
-            !movie->st[i].st->codec->channel_layout) {
300
+        if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
301
+            !movie->st[i].st->codecpar->channel_layout) {
302 302
             ret = guess_channel_layout(&movie->st[i], i, ctx);
303 303
             if (ret < 0)
304 304
                 return ret;
... ...
@@ -320,7 +329,7 @@ static av_cold void movie_uninit(AVFilterContext *ctx)
320 320
     for (i = 0; i < ctx->nb_outputs; i++) {
321 321
         av_freep(&ctx->output_pads[i].name);
322 322
         if (movie->st[i].st)
323
-            avcodec_close(movie->st[i].st->codec);
323
+            avcodec_free_context(&movie->st[i].codec_ctx);
324 324
     }
325 325
     av_freep(&movie->st);
326 326
     av_freep(&movie->out_index);
... ...
@@ -337,17 +346,17 @@ static int movie_query_formats(AVFilterContext *ctx)
337 337
 
338 338
     for (i = 0; i < ctx->nb_outputs; i++) {
339 339
         MovieStream *st = &movie->st[i];
340
-        AVCodecContext *c = st->st->codec;
340
+        AVCodecParameters *c = st->st->codecpar;
341 341
         AVFilterLink *outlink = ctx->outputs[i];
342 342
 
343 343
         switch (c->codec_type) {
344 344
         case AVMEDIA_TYPE_VIDEO:
345
-            list[0] = c->pix_fmt;
345
+            list[0] = c->format;
346 346
             if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
347 347
                 return ret;
348 348
             break;
349 349
         case AVMEDIA_TYPE_AUDIO:
350
-            list[0] = c->sample_fmt;
350
+            list[0] = c->format;
351 351
             if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
352 352
                 return ret;
353 353
             list[0] = c->sample_rate;
... ...
@@ -370,7 +379,7 @@ static int movie_config_output_props(AVFilterLink *outlink)
370 370
     MovieContext *movie  = ctx->priv;
371 371
     unsigned out_id = FF_OUTLINK_IDX(outlink);
372 372
     MovieStream *st = &movie->st[out_id];
373
-    AVCodecContext *c = st->st->codec;
373
+    AVCodecParameters *c = st->st->codecpar;
374 374
 
375 375
     outlink->time_base = st->st->time_base;
376 376
 
... ...
@@ -429,7 +438,7 @@ static int rewind_file(AVFilterContext *ctx)
429 429
     }
430 430
 
431 431
     for (i = 0; i < ctx->nb_outputs; i++) {
432
-        avcodec_flush_buffers(movie->st[i].st->codec);
432
+        avcodec_flush_buffers(movie->st[i].codec_ctx);
433 433
         movie->st[i].done = 0;
434 434
     }
435 435
     movie->eof = 0;
... ...
@@ -502,13 +511,13 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
502 502
     if (!frame)
503 503
         return AVERROR(ENOMEM);
504 504
 
505
-    frame_type = st->st->codec->codec_type;
505
+    frame_type = st->st->codecpar->codec_type;
506 506
     switch (frame_type) {
507 507
     case AVMEDIA_TYPE_VIDEO:
508
-        ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);
508
+        ret = avcodec_decode_video2(st->codec_ctx, frame, &got_frame, pkt);
509 509
         break;
510 510
     case AVMEDIA_TYPE_AUDIO:
511
-        ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);
511
+        ret = avcodec_decode_audio4(st->codec_ctx, frame, &got_frame, pkt);
512 512
         break;
513 513
     default:
514 514
         ret = AVERROR(ENOSYS);
... ...
@@ -522,7 +531,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
522 522
         movie->pkt.data = NULL;
523 523
         return 0;
524 524
     }
525
-    if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
525
+    if (!ret || st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
526 526
         ret = pkt->size;
527 527
 
528 528
     pkt->data += ret;
... ...
@@ -543,7 +552,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
543 543
     ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
544 544
             describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
545 545
 
546
-    if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
546
+    if (st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
547 547
         if (frame->format != outlink->format) {
548 548
             av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
549 549
                 av_get_pix_fmt_name(outlink->format),