Unified · Split
| @@ -60,12 +60,11 @@ static int audio_frame_count = 0; · 59 unmodified lines | |||
| 60 | * appropriate to your needs. Look for the use of api_mode in this example to | 60 | * appropriate to your needs. Look for the use of api_mode in this example to |
| 61 | * see what are the differences of API usage between them */ | 61 | * see what are the differences of API usage between them */ |
| 62 | enum { | 62 | enum { |
| 63 | API_MODE_OLD = 0, /* old method, deprecated */ | ||
| 64 | API_MODE_NEW_API_REF_COUNT = 1, /* new method, using the frame reference counting */ | 63 | API_MODE_NEW_API_REF_COUNT = 1, /* new method, using the frame reference counting */ |
| 65 | API_MODE_NEW_API_NO_REF_COUNT = 2, /* new method, without reference counting */ | 64 | API_MODE_NEW_API_NO_REF_COUNT = 2, /* new method, without reference counting */ |
| 66 | }; | 65 | }; |
| 67 | 66 | ||
| 68 | static int api_mode = API_MODE_OLD; | 67 | static int api_mode = API_MODE_NEW_API_NO_REF_COUNT; |
| 69 | 68 | ||
| 70 | static int decode_packet(int *got_frame, int cached) | 69 | static int decode_packet(int *got_frame, int cached) |
| 71 | { | 70 | { |
| @@ -243,8 +242,7 @@ int main (int argc, char **argv) · 171 unmodified lines | |||
| 243 | } | 242 | } |
| 244 | if (argc == 5) { | 243 | if (argc == 5) { |
| 245 | const char *mode = argv[1] + strlen("-refcount="); | 244 | const char *mode = argv[1] + strlen("-refcount="); |
| 246 | if (!strcmp(mode, "old")) api_mode = API_MODE_OLD; | 245 | if (!strcmp(mode, "new_norefcount")) api_mode = API_MODE_NEW_API_NO_REF_COUNT; |
| 247 | else if (!strcmp(mode, "new_norefcount")) api_mode = API_MODE_NEW_API_NO_REF_COUNT; | ||
| 248 | else if (!strcmp(mode, "new_refcount")) api_mode = API_MODE_NEW_API_REF_COUNT; | 246 | else if (!strcmp(mode, "new_refcount")) api_mode = API_MODE_NEW_API_REF_COUNT; |
| 249 | else { | 247 | else { |
| 250 | fprintf(stderr, "unknow mode '%s'\n", mode); | 248 | fprintf(stderr, "unknow mode '%s'\n", mode); |
| @@ -315,12 +313,7 @@ int main (int argc, char **argv) · 64 unmodified lines | |||
| 315 | goto end; | 313 | goto end; |
| 316 | } | 314 | } |
| 317 | 315 | ||
| 318 | /* When using the new API, you need to use the libavutil/frame.h API, while | 316 | frame = av_frame_alloc(); |
| 319 | * the classic frame management is available in libavcodec */ | ||
| 320 | if (api_mode == API_MODE_OLD) | ||
| 321 | frame = avcodec_alloc_frame(); | ||
| 322 | else | ||
| 323 | frame = av_frame_alloc(); | ||
| 324 | if (!frame) { | 317 | if (!frame) { |
| 325 | fprintf(stderr, "Could not allocate frame\n"); | 318 | fprintf(stderr, "Could not allocate frame\n"); |
| 326 | ret = AVERROR(ENOMEM); | 319 | ret = AVERROR(ENOMEM); |
| @@ -397,10 +390,7 @@ end: · 70 unmodified lines | |||
| 397 | fclose(video_dst_file); | 390 | fclose(video_dst_file); |
| 398 | if (audio_dst_file) | 391 | if (audio_dst_file) |
| 399 | fclose(audio_dst_file); | 392 | fclose(audio_dst_file); |
| 400 | if (api_mode == API_MODE_OLD) | 393 | av_frame_free(&frame); |
| 401 | avcodec_free_frame(&frame); | ||
| 402 | else | ||
| 403 | av_frame_free(&frame); | ||
| 404 | av_free(video_dst_data[0]); | 394 | av_free(video_dst_data[0]); |
| 405 | 395 | ||
| 406 | return ret < 0; | 396 | return ret < 0; |