1 /*
2 * Copyright 2010 Stephan Aßmus <superstippi@gmx.de>. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include "CodecTable.h"
8
9 extern "C" {
10 #include "avcodec.h"
11 #include "avformat.h"
12 }
13
14
15 struct AVInputFamily gAVInputFamilies[] = {
16 { B_AIFF_FORMAT_FAMILY, "aiff" },
17 { B_AVI_FORMAT_FAMILY, "avi" },
18 { B_MPEG_FORMAT_FAMILY, "mpeg" },
19 { B_QUICKTIME_FORMAT_FAMILY, "mov" },
20 { B_ANY_FORMAT_FAMILY, NULL}
21 };
22
23 static const int32 sMaxFormatCount = 1024;
24 media_format gAVCodecFormats[sMaxFormatCount];
25
26
27 status_t
build_decoder_formats(media_format ** _formats,size_t * _count)28 build_decoder_formats(media_format** _formats, size_t* _count)
29 {
30 BMediaFormats mediaFormats;
31 if (mediaFormats.InitCheck() != B_OK)
32 return B_ERROR;
33
34 int32 index = 0;
35 void* cookie = NULL;
36 const AVCodec* codec = NULL;
37 while ((codec = av_codec_iterate(&cookie)) != NULL) {
38 if (index >= sMaxFormatCount) {
39 fprintf(stderr, "Maximum format count reached for auto-generated "
40 "AVCodec to media_format mapping, but there are still more "
41 "AVCodecs compiled into libavcodec!\n");
42 break;
43 }
44 media_format format;
45 // Determine media type
46 switch (codec->type) {
47 case AVMEDIA_TYPE_VIDEO:
48 format.type = B_MEDIA_ENCODED_VIDEO;
49 break;
50 case AVMEDIA_TYPE_AUDIO:
51 format.type = B_MEDIA_ENCODED_AUDIO;
52 break;
53 default:
54 // ignore this AVCodec
55 continue;
56 }
57
58 media_format_description description;
59 memset(description._reserved_, 0, sizeof(description._reserved_));
60 memset(description.u._reserved_, 0, sizeof(description.u._reserved_));
61
62 // Hard-code everything to B_MISC_FORMAT_FAMILY to ease matching
63 // later on.
64 description.family = B_MISC_FORMAT_FAMILY;
65 description.u.misc.file_format = 'ffmp';
66 description.u.misc.codec = codec->id;
67
68 format.require_flags = 0;
69 format.deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
70
71 if (mediaFormats.MakeFormatFor(&description, 1, &format) != B_OK)
72 return B_ERROR;
73
74 gAVCodecFormats[index] = format;
75
76 index++;
77 }
78
79 *_formats = gAVCodecFormats;
80 *_count = index;
81
82 return B_OK;
83 }
84
85