xref: /haiku/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp (revision 981f1b1135291a4fca290fbdf69910dc2f24abdd)
1 /*
2  * Copyright (C) 2001 Carlos Hasan
3  * Copyright (C) 2001 François Revol
4  * Copyright (C) 2001 Axel Dörfler
5  * Copyright (C) 2004 Marcus Overhagen
6  * Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>
7  *
8  * All rights reserved. Distributed under the terms of the MIT License.
9  */
10 
11 //! libavcodec/libavformat based Decoder and Reader plugin for Haiku
12 
13 #include "FFmpegPlugin.h"
14 
15 #include <stdio.h>
16 
17 #include <new>
18 
19 extern "C" {
20 	#include "avformat.h"
21 }
22 
23 #include "AVCodecDecoder.h"
24 #include "AVFormatReader.h"
25 #include "CodecTable.h"
26 
27 
28 FFmpegPlugin::GlobalInitilizer::GlobalInitilizer()
29 {
30 	av_register_all();
31 		// This will also call av_codec_init() by registering codecs.
32 }
33 
34 
35 FFmpegPlugin::GlobalInitilizer::~GlobalInitilizer()
36 {
37 	// TODO: uninit anything here?
38 }
39 
40 
41 FFmpegPlugin::GlobalInitilizer FFmpegPlugin::sInitilizer;
42 
43 
44 // #pragma mark -
45 
46 
47 Decoder*
48 FFmpegPlugin::NewDecoder(uint index)
49 {
50 // TODO: Confirm we can check index here.
51 //	if (index == 0)
52 		return new(std::nothrow) AVCodecDecoder();
53 //	return NULL;
54 }
55 
56 
57 Reader*
58 FFmpegPlugin::NewReader()
59 {
60 	return new(std::nothrow) AVFormatReader();
61 }
62 
63 
64 status_t
65 FFmpegPlugin::GetSupportedFormats(media_format** formats, size_t* count)
66 {
67 	BMediaFormats mediaFormats;
68 	if (mediaFormats.InitCheck() != B_OK)
69 		return B_ERROR;
70 
71 	for (int i = 0; i < gCodecCount; i++) {
72 		media_format_description description;
73 		description.family = gCodecTable[i].family;
74 		switch(description.family) {
75 			case B_WAV_FORMAT_FAMILY:
76 				description.u.wav.codec = gCodecTable[i].fourcc;
77 				break;
78 			case B_AIFF_FORMAT_FAMILY:
79 				description.u.aiff.codec = gCodecTable[i].fourcc;
80 				break;
81 			case B_AVI_FORMAT_FAMILY:
82 				description.u.avi.codec = gCodecTable[i].fourcc;
83 				break;
84 			case B_MPEG_FORMAT_FAMILY:
85 				description.u.mpeg.id = gCodecTable[i].fourcc;
86 				break;
87 			case B_QUICKTIME_FORMAT_FAMILY:
88 				description.u.quicktime.codec = gCodecTable[i].fourcc;
89 				break;
90 			case B_MISC_FORMAT_FAMILY:
91 				description.u.misc.file_format =
92 					(uint32)(gCodecTable[i].fourcc >> 32);
93 				description.u.misc.codec = (uint32) gCodecTable[i].fourcc;
94 				break;
95 			default:
96 				break;
97 		}
98 		media_format format;
99 		format.type = gCodecTable[i].type;
100 		format.require_flags = 0;
101 		format.deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
102 		if (mediaFormats.MakeFormatFor(&description, 1, &format) != B_OK)
103 			return B_ERROR;
104 		gAVCodecFormats[i] = format;
105 	}
106 
107 	*formats = gAVCodecFormats;
108 	*count = gCodecCount;
109 	return B_OK;
110 }
111 
112 
113 MediaPlugin*
114 instantiate_plugin()
115 {
116 	return new(std::nothrow) FFmpegPlugin;
117 }
118 
119