Permalink
Browse files

Reduce the number of deprecated libav* APIs in use

There's still one left in FFission before we could update libav again.

Maybe we should use buffered avio after all and not mess with URLContext so much.

git-svn-id: https://svn.perian.org/trunk@1525 621663c8-3916-0410-8f58-edc14a8543d5
  • Loading branch information...
astrange
astrange committed Nov 13, 2012
1 parent c5adc73 commit c178e33988f2584088c74d2518eb9b81abb26913
Showing with 51 additions and 42 deletions.
  1. +1 −2 FFissionCodec/FFissionCodec.cpp
  2. +1 −3 FFissionCodec/FFissionDecoder.cpp
  3. +43 −32 ff_MovieImport.c
  4. +5 −4 ff_dataref.c
  5. +1 −1 ff_private.h
@@ -36,8 +36,7 @@ FFissionCodec::FFissionCodec(AudioComponentInstance inInstance) : ACBaseCodec(in
{
FFInitFFmpeg();
// FIXME avcodec_alloc_context3
avContext = avcodec_alloc_context2(AVMEDIA_TYPE_AUDIO);
avContext = avcodec_alloc_context3(NULL);
avCodec = NULL;
}
@@ -126,8 +126,6 @@ FFissionDecoder::FFissionDecoder(AudioComponentInstance inInstance) : FFissionCo
int initialMap[6] = {0, 1, 2, 3, 4, 5};
memcpy(fullChannelMap, initialMap, sizeof(initialMap));
// FIXME avcodec_get_context_defaults3
avcodec_get_context_defaults2(avContext, AVMEDIA_TYPE_AUDIO);
parser = NULL;
}
@@ -382,8 +380,8 @@ void FFissionDecoder::OpenAVCodec()
CodecID codecID = FFFourCCToCodecID(mInputFormat.mFormatID);
avCodec = avcodec_find_decoder(codecID);
avcodec_get_context_defaults3(avContext, avCodec);
FFASBDToAVCodecContext(&mInputFormat, avContext);
avContext->codec_id = codecID;
if (avContext->sample_rate == 0) {
Codecprintf(NULL, "Invalid sample rate %d\n", avContext->sample_rate);
@@ -89,8 +89,11 @@ ComponentResult FFAvi_MovieImportClose(ff_global_ptr storage, ComponentInstance
if(storage->stream_map)
av_free(storage->stream_map);
if(storage->format_context)
av_close_input_file(storage->format_context);
if(storage->format_context) {
if (storage->format_context->pb)
avio_close(storage->format_context->pb);
avformat_close_input(&storage->format_context);
}
int i;
for(i=0; i<16; i++)
@@ -215,44 +218,44 @@ ComponentResult FFAvi_MovieImportValidate(ff_global_ptr storage, const FSSpec *t
// this function is a small avi parser to get the video track's fourcc as
// fast as possible, so we can decide whether we can handle the necessary
// image description extensions for the format in ValidateDataRef() quickly
OSType get_avi_strf_fourcc(ByteIOContext *pb)
OSType get_avi_strf_fourcc(AVIOContext *pb)
{
OSType tag, subtag;
unsigned int size;
if (get_be32(pb) != 'RIFF')
if (avio_rb32(pb) != 'RIFF')
return 0;
// file size
get_le32(pb);
avio_rl32(pb);
if (get_be32(pb) != 'AVI ')
if (avio_rb32(pb) != 'AVI ')
return 0;
while (!url_feof(pb)) {
tag = get_be32(pb);
size = get_le32(pb);
while (!pb->eof_reached) {
tag = avio_rb32(pb);
size = avio_rl32(pb);
if (tag == 'LIST') {
subtag = get_be32(pb);
subtag = avio_rb32(pb);
// only lists we care about: hdrl & strl, so skip the rest
if (subtag != 'hdrl' && subtag != 'strl')
url_fskip(pb, size - 4 + (size & 1));
avio_skip(pb, size - 4 + (size & 1));
} else if (tag == 'strf') {
// 16-byte offset to the fourcc
url_fskip(pb, 16);
return get_be32(pb);
avio_skip(pb, 16);
return avio_rb32(pb);
} else if (tag == 'strh'){
// 4-byte offset to the fourcc
OSType tag1 = get_be32(pb);
OSType tag1 = avio_rb32(pb);
if(tag1 == 'iavs' || tag1 == 'ivas')
return get_be32(pb);
return avio_rb32(pb);
else
url_fskip(pb, size + (size & 1) - 4);
avio_skip(pb, size + (size & 1) - 4);
} else
url_fskip(pb, size + (size & 1));
avio_skip(pb, size + (size & 1));
}
return 0;
}
@@ -263,7 +266,7 @@ ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle d
DataHandler dataHandler = NULL;
uint8_t buf[PROBE_BUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE] = {0};
AVProbeData pd;
ByteIOContext *byteContext;
AVIOContext *byteContext;
/* default */
*valid = 0;
@@ -297,7 +300,7 @@ ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle d
if (id == CODEC_ID_MJPEG || id == CODEC_ID_DVVIDEO || id == CODEC_ID_RAWVIDEO || id == CODEC_ID_MSVIDEO1 || id == CODEC_ID_MSRLE)
*valid = 0;
url_fclose(byteContext);
avio_close(byteContext);
}
}
@@ -340,9 +343,8 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
Track *usedTrack, TimeValue atTime, TimeValue *addedDuration, long inFlags, long *outFlags)
{
ComponentResult result = noErr;
ByteIOContext *byteContext;
AVIOContext *byteContext;
AVFormatContext *ic = NULL;
AVFormatParameters params;
OSType mediaType;
Media media;
int count, hadIndex, j;
@@ -362,36 +364,41 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
require_noerr(result, bail);
/* Open the Format Context */
memset(&params, 0, sizeof(params));
result = av_open_input_stream(&ic, byteContext, "", storage->format, &params);
ic = avformat_alloc_context();
ic->flags |= AVFMT_FLAG_CUSTOM_IO;
ic->pb = byteContext;
result = avformat_open_input(&ic, "", storage->format, NULL);
require_noerr(result,bail);
storage->format_context = ic;
ic = NULL;
int nb_streams = storage->format_context->nb_streams;
if (ic->nb_streams >= 16)
if (nb_streams >= 16)
goto bail;
// AVIs without an index currently add a few entries to the index so it can
// determine codec parameters. Check for index existence here before it
// reads any packets.
hadIndex = 1;
for (j = 0; j < ic->nb_streams; j++) {
if (ic->streams[j]->nb_index_entries <= 1)
for (j = 0; j < nb_streams; j++) {
if (storage->format_context->streams[j]->nb_index_entries <= 1)
{
hadIndex = 0;
break;
}
}
/* Get the Stream Infos if not already read */
result = av_find_stream_info(ic);
result = avformat_find_stream_info(storage->format_context, NULL);
// -1 means it couldn't understand at least one stream
// which might just mean we don't have its video decoder enabled
if(result < 0 && result != -1)
goto bail;
// we couldn't find any streams, bail with an error.
if(ic->nb_streams == 0) {
if(nb_streams == 0) {
result = -1; //is there a more appropriate error code?
goto bail;
}
@@ -407,7 +414,7 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
storage->map_count = 1;
prepare_track(storage, targetTrack, dataRef, dataRefType);
} else {
storage->map_count = ic->nb_streams;
storage->map_count = nb_streams;
result = prepare_movie(storage, theMovie, dataRef, dataRefType);
if (result != 0)
goto bail;
@@ -461,9 +468,10 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
*outFlags |= movieImportResultComplete;
} else if(inFlags & movieImportWithIdle) {
if(addedDuration && ic->duration > 0) {
int64_t duration = storage->format_context->duration;
if(addedDuration && duration > 0) {
TimeScale movieTimeScale = GetMovieTimeScale(theMovie);
*addedDuration = movieTimeScale * ic->duration / AV_TIME_BASE;
*addedDuration = movieTimeScale * duration / AV_TIME_BASE;
//create a placeholder track so that progress displays correctly.
create_placeholder_track(storage->movie, &storage->placeholderTrack, *addedDuration, dataRef, dataRefType);
@@ -472,7 +480,7 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
//suggest a speed that's faster than the bare minimum.
//if there's an error, the data handler probably doesn't support
//this, so we can just ignore.
DataHPlaybackHints(storage->dataHandler, 0, 0, -1, (storage->dataSize * 1.15) / ((double)ic->duration / AV_TIME_BASE));
DataHPlaybackHints(storage->dataHandler, 0, 0, -1, (storage->dataSize * 1.15) / ((double)duration / AV_TIME_BASE));
}
//import with idle. Decode a little bit of data now.
@@ -493,6 +501,9 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
if (result == -1)
result = invalidMovie; // a bit better error message
if (ic)
avformat_free_context(ic);
return result;
} /* FFAvi_MovieImportDataRef */
@@ -22,6 +22,7 @@
#include <QuickTime/QuickTime.h>
#include <libavformat/avformat.h>
#include <libavformat/avio_internal.h>
struct _dataref_private {
Handle dataRef;
@@ -214,7 +215,7 @@ URLProtocol dataref_protocol = {
};
/* This is the public function to open bytecontext withs datarefs */
OSStatus url_open_dataref(ByteIOContext **pb, Handle dataRef, OSType dataRefType, DataHandler *dataHandler, Boolean *wideSupport, int64_t *dataSize)
OSStatus url_open_dataref(AVIOContext **pb, Handle dataRef, OSType dataRefType, DataHandler *dataHandler, Boolean *wideSupport, int64_t *dataSize)
{
URLContext *uc;
URLProtocol *up;
@@ -227,7 +228,7 @@ OSStatus url_open_dataref(ByteIOContext **pb, Handle dataRef, OSType dataRefType
up = &dataref_protocol;
//FIXME use url_alloc() with better fake protocol
//FIXME use url_alloc() with better fake protocol, and avoid using avio_internal
uc = av_mallocz(sizeof(URLContext));
if(!uc) {
err = -ENOMEM;
@@ -247,9 +248,9 @@ OSStatus url_open_dataref(ByteIOContext **pb, Handle dataRef, OSType dataRefType
av_free(uc);
return err;
}
err = url_fdopen(pb, uc);
err = ffio_fdopen(pb, uc);
if(err < 0) {
url_close(uc);
ffurl_close(uc);
return err;
}
@@ -90,7 +90,7 @@ typedef ff_global_context *ff_global_ptr;
ComponentResult check_system();
/* Public interface of the DataRef interface */
OSStatus url_open_dataref(ByteIOContext **pb, Handle dataRef, OSType dataRefType, DataHandler *dataHandler, Boolean *wideSupport, int64_t *dataSize);
OSStatus url_open_dataref(AVIOContext **pb, Handle dataRef, OSType dataRefType, DataHandler *dataHandler, Boolean *wideSupport, int64_t *dataSize);
/* Import routines */
int prepare_track(ff_global_ptr storage, Track targetTrack, Handle dataRef, OSType dataRefType);

0 comments on commit c178e33

Please sign in to comment.