xref: /haiku/src/add-ons/media/plugins/ffmpeg/CodecTable.cpp (revision 410ed2fbba58819ac21e27d3676739728416761d)
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
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 	AVCodec* codec = NULL;
36 	while ((codec = av_codec_next(codec)) != NULL) {
37 		if (index >= sMaxFormatCount) {
38 			fprintf(stderr, "Maximum format count reached for auto-generated "
39 				"AVCodec to media_format mapping, but there are still more "
40 				"AVCodecs compiled into libavcodec!\n");
41 			break;
42 		}
43 		media_format format;
44 		// Determine media type
45 		switch (codec->type) {
46 			case AVMEDIA_TYPE_VIDEO:
47 				format.type = B_MEDIA_ENCODED_VIDEO;
48 				break;
49 			case AVMEDIA_TYPE_AUDIO:
50 				format.type = B_MEDIA_ENCODED_AUDIO;
51 				break;
52 			default:
53 				// ignore this AVCodec
54 				continue;
55 		}
56 
57 		media_format_description description;
58 		memset(&description, 0, sizeof(description));
59 
60 		// Hard-code everything to B_MISC_FORMAT_FAMILY to ease matching
61 		// later on.
62 		description.family = B_MISC_FORMAT_FAMILY;
63 		description.u.misc.file_format = 'ffmp';
64 		description.u.misc.codec = codec->id;
65 
66 		format.require_flags = 0;
67 		format.deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
68 
69 		if (mediaFormats.MakeFormatFor(&description, 1, &format) != B_OK)
70 			return B_ERROR;
71 
72 		gAVCodecFormats[index] = format;
73 
74 		index++;
75 	}
76 
77 	*_formats = gAVCodecFormats;
78 	*_count = index;
79 
80 	return B_OK;
81 }
82 
83