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 19extern "C" { 20 #include "avcodec.h" 21 #include "avformat.h" 22} 23 24#include "AVCodecDecoder.h" 25#include "AVCodecEncoder.h" 26#include "AVFormatReader.h" 27#include "AVFormatWriter.h" 28#include "CodecTable.h" 29#include "EncoderTable.h" 30#include "MuxerTable.h" 31 32 33//#define TRACE_FFMPEG_PLUGIN 34#ifdef TRACE_FFMPEG_PLUGIN 35# define TRACE printf 36#else 37# define TRACE(a...) 38#endif 39 40#define ERROR(a...) fprintf(stderr, a) 41 42 43// #pragma mark - 44 45 46Decoder* 47FFmpegPlugin::NewDecoder(uint index) 48{ 49// TODO: Confirm we can check index here. 50// if (index == 0) 51 return new(std::nothrow) AVCodecDecoder(); 52// return NULL; 53} 54 55 56Reader* 57FFmpegPlugin::NewReader() 58{ 59 return new(std::nothrow) AVFormatReader(); 60} 61 62 63status_t 64FFmpegPlugin::GetSupportedFormats(media_format** _formats, size_t* _count) 65{ 66 return build_decoder_formats(_formats, _count); 67} 68 69 70Writer* 71FFmpegPlugin::NewWriter() 72{ 73 return new(std::nothrow) AVFormatWriter(); 74} 75 76 77status_t 78FFmpegPlugin::GetSupportedFileFormats(const media_file_format** _fileFormats, 79 size_t* _count) 80{ 81 *_fileFormats = gMuxerTable; 82 *_count = gMuxerCount; 83 return B_OK; 84} 85 86 87Encoder* 88FFmpegPlugin::NewEncoder(const media_codec_info& codecInfo) 89{ 90 for (size_t i = 0; i < gEncoderCount; i++) { 91 if (codecInfo.sub_id == gEncoderTable[i].codec_info.sub_id) { 92 return new(std::nothrow)AVCodecEncoder(codecInfo.sub_id, 93 gEncoderTable[i].bit_rate_scale); 94 } 95 } 96 return NULL; 97} 98 99 100Encoder* 101FFmpegPlugin::NewEncoder(const media_format& format) 102{ 103 for (size_t i = 0; i < gEncoderCount; i++) { 104 if (format.type == gEncoderTable[i].output_type) { 105 return new(std::nothrow)AVCodecEncoder( 106 gEncoderTable[i].codec_info.sub_id, 107 gEncoderTable[i].bit_rate_scale); 108 } 109 } 110 return NULL; 111} 112 113 114status_t 115FFmpegPlugin::RegisterNextEncoder(int32* cookie, media_codec_info* _codecInfo, 116 media_format_family* _formatFamily, media_format* _inputFormat, 117 media_format* _outputFormat) 118{ 119 if (*cookie < 0 || *cookie >= (int32)gEncoderCount) 120 return B_BAD_INDEX; 121 122 *_codecInfo = gEncoderTable[*cookie].codec_info; 123 *_formatFamily = gEncoderTable[*cookie].format_family; 124 _inputFormat->type = gEncoderTable[*cookie].input_type; 125 _outputFormat->type = gEncoderTable[*cookie].output_type;; 126 127 *cookie = *cookie + 1; 128 129 return B_OK; 130} 131 132 133// #pragma mark - 134 135 136MediaPlugin* 137instantiate_plugin() 138{ 139 return new(std::nothrow) FFmpegPlugin; 140} 141 142