Cleaned up the source file names and code locations in the avcodec plugin,

unified the Reader and Decoder plugins and renamed the add-on to "ffmpeg".


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31358 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-07-01 18:52:48 +00:00
parent 007ea5873a
commit 043eaa5c3f
10 changed files with 217 additions and 189 deletions
+1 -1
View File
@@ -122,7 +122,7 @@ SYSTEM_ADD_ONS_MEDIA = cortex_audioadapter.media_addon cortex_flanger.media_addo
#legacy.media_addon
;
SYSTEM_ADD_ONS_MEDIA_PLUGINS = $(GPL_ONLY)ac3_decoder
aiff_reader asf_reader au_reader $(X86_ONLY)avcodec avi_reader
aiff_reader asf_reader au_reader avi_reader $(X86_ONLY)ffmpeg
matroska mov_reader
mp3_decoder mp3_reader
mp4_reader musepack
@@ -3,23 +3,24 @@
* Copyright (C) 2001 François Revol
* Copyright (C) 2001 Axel Dörfler
* Copyright (C) 2004 Marcus Overhagen
* Copyright (C) 2009 Stephan Amßus <superstippi@gmx.de>
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
//! libavcodec based decoder for Haiku
#include "AVCodecDecoder.h"
#include <Debug.h>
#include <OS.h>
#include <Bitmap.h>
#include <string.h>
#include "avcodecplugin.h"
#define DO_PROFILING 0
#undef TRACE
//#define TRACE_AV_CODEC
#define TRACE_AV_CODEC
#ifdef TRACE_AV_CODEC
# define TRACE(x...) printf(x)
#else
@@ -45,7 +46,7 @@ static long prof_cnt = 0;
// with CD Manager)
//#define UNREAL
avCodec::avCodec()
AVCodecDecoder::AVCodecDecoder()
: fHeader(),
fInfo(),
fInputFormat(),
@@ -61,7 +62,7 @@ avCodec::avCodec()
fBlockAlign(0),
fOutputBuffer(0)
{
TRACE("avCodec::avCodec()\n");
TRACE("AVCodecDecoder::AVCodecDecoder()\n");
// prevent multiple inits
static volatile vint32 ff_init_count = 0;
@@ -83,9 +84,9 @@ avCodec::avCodec()
}
avCodec::~avCodec()
AVCodecDecoder::~AVCodecDecoder()
{
TRACE("[%c] avCodec::~avCodec()\n", isAudio?('a'):('v'));
TRACE("[%c] AVCodecDecoder::~AVCodecDecoder()\n", isAudio?('a'):('v'));
#ifdef DO_PROFILING
if (prof_cnt > 0) {
@@ -95,7 +96,7 @@ avCodec::~avCodec()
}
#endif
if(fCodecInitDone)
if (fCodecInitDone)
avcodec_close(ffc);
free(opicture);
@@ -108,7 +109,7 @@ avCodec::~avCodec()
void
avCodec::GetCodecInfo(media_codec_info *mci)
AVCodecDecoder::GetCodecInfo(media_codec_info *mci)
{
sprintf(mci->short_name, "ff:%s", fCodec->name);
sprintf(mci->pretty_name, "%s (libavcodec %s)",
@@ -117,7 +118,7 @@ avCodec::GetCodecInfo(media_codec_info *mci)
status_t
avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
AVCodecDecoder::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
size_t infoSize)
{
if (ioEncodedFormat->type != B_MEDIA_ENCODED_AUDIO
@@ -125,7 +126,7 @@ avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
return B_ERROR;
isAudio = (ioEncodedFormat->type == B_MEDIA_ENCODED_AUDIO);
TRACE("[%c] avCodec::Setup()\n", isAudio?('a'):('v'));
TRACE("[%c] AVCodecDecoder::Setup()\n", isAudio?('a'):('v'));
if (isAudio && !fOutputBuffer)
fOutputBuffer = new char[AVCODEC_MAX_AUDIO_FRAME_SIZE];
@@ -180,11 +181,11 @@ avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
&& gCodecTable[i].fourcc == cid) {
fCodec = avcodec_find_decoder(gCodecTable[i].id);
if (!fCodec) {
TRACE("avCodec: unable to find the correct ffmpeg decoder "
TRACE("AVCodecDecoder: unable to find the correct ffmpeg decoder "
"(id = %d)!!!\n",gCodecTable[i].id);
return B_ERROR;
}
TRACE("avCodec: found decoder %s\n",fCodec->name);
TRACE("AVCodecDecoder: found decoder %s\n",fCodec->name);
if (gCodecTable[i].family == B_WAV_FORMAT_FAMILY && infoSize >= sizeof(wave_format_ex)) {
const wave_format_ex *wfmt_data
@@ -200,7 +201,7 @@ avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
}
} else {
fBlockAlign = ioEncodedFormat->u.encoded_audio.output.buffer_size;
TRACE("avCodec: extra data size %ld\n",infoSize);
TRACE("AVCodecDecoder: extra data size %ld\n",infoSize);
fExtraDataSize = infoSize;
if (fExtraDataSize) {
fExtraData = new char [fExtraDataSize];
@@ -213,13 +214,13 @@ avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
}
}
}
printf("avCodec::Setup failed!\n");
printf("AVCodecDecoder::Setup failed!\n");
return B_ERROR;
}
status_t
avCodec::Seek(uint32 seekTo,
AVCodecDecoder::Seek(uint32 seekTo,
int64 seekFrame, int64 *frame,
bigtime_t seekTime, bigtime_t *time)
{
@@ -232,13 +233,13 @@ avCodec::Seek(uint32 seekTo,
}
if (seekTo == B_MEDIA_SEEK_TO_TIME) {
TRACE("avCodec::Seek by time ");
TRACE("AVCodecDecoder::Seek by time ");
TRACE("from frame %Ld and time %.6f TO Required Time %.6f. ", fFrame, fStartTime / 1000000.0, seekTime / 1000000.0);
*frame = (int64)(seekTime * fOutputFrameRate / 1000000LL);
*time = seekTime;
} else if (seekTo == B_MEDIA_SEEK_TO_FRAME) {
TRACE("avCodec::Seek by Frame ");
TRACE("AVCodecDecoder::Seek by Frame ");
TRACE("from time %.6f and frame %Ld TO Required Frame %Ld. ", fStartTime / 1000000.0, fFrame, seekFrame);
*time = (bigtime_t)(seekFrame * 1000000LL / fOutputFrameRate);
@@ -254,9 +255,9 @@ avCodec::Seek(uint32 seekTo,
status_t
avCodec::NegotiateOutputFormat(media_format *inout_format)
AVCodecDecoder::NegotiateOutputFormat(media_format *inout_format)
{
TRACE("[%c] avCodec::NegotiateOutputFormat()\n", isAudio?('a'):('v'));
TRACE("[%c] AVCodecDecoder::NegotiateOutputFormat()\n", isAudio?('a'):('v'));
int result;
@@ -413,7 +414,7 @@ avCodec::NegotiateOutputFormat(media_format *inout_format)
status_t
avCodec::Decode(void *out_buffer, int64 *out_frameCount,
AVCodecDecoder::Decode(void *out_buffer, int64 *out_frameCount,
media_header *mh, media_decode_info *info)
{
const void *data;
@@ -429,7 +430,7 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
set_thread_priority(find_thread(NULL), B_NORMAL_PRIORITY);
#endif
// TRACE("[%c] avCodec::Decode() for time %Ld\n", isAudio?('a'):('v'), fStartTime);
// TRACE("[%c] AVCodecDecoder::Decode() for time %Ld\n", isAudio?('a'):('v'), fStartTime);
mh->start_time = fStartTime;
@@ -518,7 +519,7 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
err = GetNextChunk(&data, &size, &chunk_mh);
if (err != B_OK) {
TRACE("avCodec::Decode(): error 0x%08lx from GetNextChunk()\n", err);
TRACE("AVCodecDecoder::Decode(): error 0x%08lx from GetNextChunk()\n", err);
return err;
}
@@ -559,7 +560,7 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
// (int)(ffpicture->pts % 1000000), ffc->frame_number, ffc->frame_rate);
if (len < 0) {
printf("[%c] avCodec: error in decoding frame %lld\n",
printf("[%c] AVCodecDecoder: error in decoding frame %lld\n",
isAudio?('a'):('v'), *out_frameCount);
}
@@ -614,64 +615,3 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
return B_OK;
}
status_t
avCodecPlugin::GetSupportedFormats(media_format ** formats, size_t * count)
{
BMediaFormats mediaFormats;
if (B_OK != mediaFormats.InitCheck())
return B_ERROR;
for (int i = 0; i < num_codecs; i++) {
media_format_description description;
description.family = gCodecTable[i].family;
switch(description.family) {
case B_WAV_FORMAT_FAMILY:
description.u.wav.codec = gCodecTable[i].fourcc;
break;
case B_AIFF_FORMAT_FAMILY:
description.u.aiff.codec = gCodecTable[i].fourcc;
break;
case B_AVI_FORMAT_FAMILY:
description.u.avi.codec = gCodecTable[i].fourcc;
break;
case B_MPEG_FORMAT_FAMILY:
description.u.mpeg.id = gCodecTable[i].fourcc;
break;
case B_QUICKTIME_FORMAT_FAMILY:
description.u.quicktime.codec = gCodecTable[i].fourcc;
break;
case B_MISC_FORMAT_FAMILY:
description.u.misc.file_format =
(uint32)(gCodecTable[i].fourcc >> 32);
description.u.misc.codec = (uint32) gCodecTable[i].fourcc;
break;
default:
break;
}
media_format format;
format.type = gCodecTable[i].type;
format.require_flags = 0;
format.deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
if (B_OK != mediaFormats.MakeFormatFor(&description, 1, &format))
return B_ERROR;
avcodec_formats[i] = format;
}
*formats = avcodec_formats;
*count = num_codecs;
return B_OK;
}
Decoder *
avCodecPlugin::NewDecoder(uint index)
{
return new avCodec();
}
MediaPlugin *instantiate_plugin()
{
return new avCodecPlugin;
}
@@ -1,42 +1,30 @@
/*
* Copyright (C) 2001 Carlos Hasan. All Rights Reserved.
* Copyright (C) 2001 François Revol. All Rights Reserved.
* Copyright (C) 2001 Axel Dörfler. All Rights Reserved.
* Copyright (C) 2004 Marcus Overhagen. All Rights Reserved.
* Copyright (C) 2001 Carlos Hasan.
* Copyright (C) 2001 François Revol.
* Copyright (C) 2001 Axel Dörfler.
* Copyright (C) 2004 Marcus Overhagen.
* Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>.
*
* Distributed under the terms of the MIT License.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef AVCODEC_DECODER_H
#define AVCODEC_DECODER_H
//! libavcodec based decoder for Haiku
#ifndef __AVCODEC_PLUGIN_H__
#define __AVCODEC_PLUGIN_H__
#include <MediaFormats.h>
#include "ReaderPlugin.h"
#include "DecoderPlugin.h"
#include "ReaderPlugin.h"
//#define DO_PROFILING
#include "CodecTable.h"
#include "gfx_util.h"
struct codec_table {
CodecID id;
media_type type;
media_format_family family;
uint64 fourcc;
const char* prettyname;
};
extern const struct codec_table gCodecTable[];
extern const int num_codecs;
extern media_format avcodec_formats[];
class avCodec : public Decoder {
class AVCodecDecoder : public Decoder {
public:
avCodec();
AVCodecDecoder();
virtual ~avCodec();
virtual ~AVCodecDecoder();
virtual void GetCodecInfo(media_codec_info* mci);
@@ -59,7 +47,7 @@ protected:
media_header fHeader;
media_decode_info fInfo;
friend class avCodecInputStream;
// friend class avCodecInputStream;
private:
media_format fInputFormat;
@@ -100,12 +88,4 @@ private:
};
class avCodecPlugin : public DecoderPlugin {
public:
Decoder* NewDecoder(uint index);
status_t GetSupportedFormats(media_format** formats,
size_t* count);
};
#endif
#endif // AVCODEC_DECODER_H
@@ -87,14 +87,6 @@ static URLProtocol position_io_protocol = {
};
void
avcodec_register_all()
{
// av_register_all() will call libavcodec's avcodec_register_all(),
// but we do not link against libavcodec in this plugin.
}
static int
init_libavformat()
{
@@ -103,9 +95,6 @@ init_libavformat()
}
static int dummy = init_libavformat();
// #pragma mark - AVFormatReader
@@ -218,18 +207,3 @@ AVFormatReader::GetNextChunk(void* _cookie, const void** chunkBuffer,
}
// #pragma mark -
Reader*
AVFormatPlugin::NewReader()
{
return new(std::nothrow) AVFormatReader;
}
MediaPlugin*
instantiate_plugin()
{
return new(std::nothrow) AVFormatPlugin;
}
@@ -46,11 +46,4 @@ private:
};
class AVFormatPlugin : public ReaderPlugin {
public:
Reader* NewReader();
};
MediaPlugin *instantiate_plugin();
#endif // AV_FORMAT_READER_H
@@ -1,23 +1,12 @@
/******************************************************************************
/
/ File: codectbl.cpp
/
/ Description: FFMpeg Generic Decoder for BeOS Release 5.
/
/ Disclaimer: This decoder is based on undocumented APIs.
/ Therefore it is likely, if not certain, to break in future
/ versions of BeOS. This piece of software is in no way
/ connected to or even supported by Be, Inc.
/
/ Copyright (C) 2001 François Revol. All Rights Reserved.
/ Some code from MPEG I Decoder from Carlos Hasan.
/ Had some help from Axeld
/
******************************************************************************/
/*
* Copyright (C) 2001 Carlos Hasan. All Rights Reserved.
* Copyright (C) 2001 François Revol. All Rights Reserved.
* Copyright (C) 2001 Axel Dörfler. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
#include <MediaDefs.h>
#include "avcodecplugin.h"
#include "CodecTable.h"
#define HAS_WMA_AUDIO
//#define HAS_MACE_AUDIO
@@ -214,8 +203,8 @@ const struct codec_table gCodecTable[] = {
{CODEC_ID_NONE, B_MEDIA_UNKNOWN_TYPE, B_ANY_FORMAT_FAMILY, 0, "null codec !!!"}
};
const int num_codecs = (sizeof(gCodecTable) / sizeof(codec_table) - 1);
const int gCodecCount = (sizeof(gCodecTable) / sizeof(codec_table) - 1);
media_format avcodec_formats[sizeof(gCodecTable)];
media_format gAVCodecFormats[sizeof(gCodecTable)];
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2001 Carlos Hasan. All Rights Reserved.
* Copyright (C) 2001 François Revol. All Rights Reserved.
* Copyright (C) 2001 Axel Dörfler. All Rights Reserved.
* Copyright (C) 2004 Marcus Overhagen. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
//! libavcodec based decoder for Haiku
#ifndef CODEC_TABLE_H
#define CODEC_TABLE_H
#include <MediaDefs.h>
#include <MediaFormats.h>
#include "gfx_util.h"
struct codec_table {
CodecID id;
media_type type;
media_format_family family;
uint64 fourcc;
const char* prettyname;
};
extern const struct codec_table gCodecTable[];
extern const int gCodecCount;
extern media_format gAVCodecFormats[];
#endif // CODEC_TABLE_H
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2001 Carlos Hasan
* Copyright (C) 2001 François Revol
* Copyright (C) 2001 Axel Dörfler
* Copyright (C) 2004 Marcus Overhagen
* Copyright (C) 2009 Stephan Aßmus <[email protected]>
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
//! libavcodec/libavformat based Decoder and Reader plugin for Haiku
#include "FFmpegPlugin.h"
#include <new>
#include "AVCodecDecoder.h"
#include "AVFormatReader.h"
#include "CodecTable.h"
Decoder*
FFmpegPlugin::NewDecoder(uint index)
{
// TODO: Confirm we can check index here.
// if (index == 0)
return new(std::nothrow) AVCodecDecoder();
// return NULL;
}
Reader*
FFmpegPlugin::NewReader()
{
return new(std::nothrow) AVFormatReader();
}
status_t
FFmpegPlugin::GetSupportedFormats(media_format** formats, size_t* count)
{
BMediaFormats mediaFormats;
if (mediaFormats.InitCheck() != B_OK)
return B_ERROR;
for (int i = 0; i < gCodecCount; i++) {
media_format_description description;
description.family = gCodecTable[i].family;
switch(description.family) {
case B_WAV_FORMAT_FAMILY:
description.u.wav.codec = gCodecTable[i].fourcc;
break;
case B_AIFF_FORMAT_FAMILY:
description.u.aiff.codec = gCodecTable[i].fourcc;
break;
case B_AVI_FORMAT_FAMILY:
description.u.avi.codec = gCodecTable[i].fourcc;
break;
case B_MPEG_FORMAT_FAMILY:
description.u.mpeg.id = gCodecTable[i].fourcc;
break;
case B_QUICKTIME_FORMAT_FAMILY:
description.u.quicktime.codec = gCodecTable[i].fourcc;
break;
case B_MISC_FORMAT_FAMILY:
description.u.misc.file_format =
(uint32)(gCodecTable[i].fourcc >> 32);
description.u.misc.codec = (uint32) gCodecTable[i].fourcc;
break;
default:
break;
}
media_format format;
format.type = gCodecTable[i].type;
format.require_flags = 0;
format.deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
if (mediaFormats.MakeFormatFor(&description, 1, &format) != B_OK)
return B_ERROR;
gAVCodecFormats[i] = format;
}
*formats = gAVCodecFormats;
*count = gCodecCount;
return B_OK;
}
MediaPlugin*
instantiate_plugin()
{
return new(std::nothrow) FFmpegPlugin;
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2001 Carlos Hasan. All Rights Reserved.
* Copyright (C) 2001 François Revol. All Rights Reserved.
* Copyright (C) 2001 Axel Dörfler. All Rights Reserved.
* Copyright (C) 2004 Marcus Overhagen. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
//! libavcodec based decoder for Haiku
#ifndef FFMPEG_PLUGIN_H
#define FFMPEG_PLUGIN_H
#include <MediaFormats.h>
#include "DecoderPlugin.h"
#include "ReaderPlugin.h"
class FFmpegPlugin : public ReaderPlugin, public DecoderPlugin {
public:
virtual Reader* NewReader();
virtual Decoder* NewDecoder(uint index);
virtual status_t GetSupportedFormats(media_format** formats,
size_t* count);
};
#endif // FFMPEG_PLUGIN_H
+8 -13
View File
@@ -9,14 +9,19 @@ SubDirHdrs [ FDirName $(SUBDIR) libavformat ] ;
SubDirHdrs [ FDirName $(SUBDIR) libavutil ] ;
SubDirHdrs [ FDirName $(SUBDIR) libswscale ] ;
Addon avcodec :
avcodec.cpp
codectbl.cpp
Addon ffmpeg :
AVCodecDecoder.cpp
AVFormatReader.cpp
CodecTable.cpp
FFmpegPlugin.cpp
gfx_conv_c.cpp
gfx_conv_c_lookup.cpp
# gfx_conv_mmx.cpp
gfx_util.cpp
:
libavformat.a
libavcodec.a
libavcodec_$(TARGET_ARCH).a
libavutil.a
@@ -26,16 +31,6 @@ Addon avcodec :
libz.a
;
Addon avformat :
AVFormatReader.cpp
:
libavformat.a
libavutil.a
be
libmedia.so
libz.a
;
SubInclude HAIKU_TOP src add-ons media plugins avcodec libavcodec ;
SubInclude HAIKU_TOP src add-ons media plugins avcodec libavformat ;
SubInclude HAIKU_TOP src add-ons media plugins avcodec libavutil ;