ffmpeg: make ffmpeg_helper() return bool

ffmpeg_try_decode() did not interpret ffmpeg_helper()'s return value
properly; migrate everything to bool to make it consistent.
This commit is contained in:
Max Kellermann 2008-10-30 19:01:23 +01:00
parent 078d83ca13
commit 7cbd9821c6
1 changed files with 21 additions and 24 deletions

View File

@ -134,18 +134,19 @@ static bool ffmpeg_init(void)
return true; return true;
} }
static int static bool
ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs), ffmpeg_helper(struct input_stream *input, bool (*callback)(BasePtrs *ptrs),
BasePtrs *ptrs) BasePtrs *ptrs)
{ {
AVFormatContext *pFormatCtx; AVFormatContext *pFormatCtx;
AVCodecContext *aCodecCtx; AVCodecContext *aCodecCtx;
AVCodec *aCodec; AVCodec *aCodec;
int ret, audioStream; int audioStream;
unsigned i; unsigned i;
FopsHelper fopshelp = { FopsHelper fopshelp = {
.url = "mpd://X", /* only the mpd:// prefix matters */ .url = "mpd://X", /* only the mpd:// prefix matters */
}; };
bool ret;
fopshelp.input = input; fopshelp.input = input;
if (ptrs && ptrs->decoder) { if (ptrs && ptrs->decoder) {
@ -157,12 +158,12 @@ ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs),
//ffmpeg works with ours "fileops" helper //ffmpeg works with ours "fileops" helper
if (av_open_input_file(&pFormatCtx, fopshelp.url, NULL, 0, NULL)!=0) { if (av_open_input_file(&pFormatCtx, fopshelp.url, NULL, 0, NULL)!=0) {
ERROR("Open failed!\n"); ERROR("Open failed!\n");
return -1; return false;
} }
if (av_find_stream_info(pFormatCtx)<0) { if (av_find_stream_info(pFormatCtx)<0) {
ERROR("Couldn't find stream info!\n"); ERROR("Couldn't find stream info!\n");
return -1; return false;
} }
audioStream = -1; audioStream = -1;
@ -175,7 +176,7 @@ ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs),
if(audioStream==-1) { if(audioStream==-1) {
ERROR("No audio stream inside!\n"); ERROR("No audio stream inside!\n");
return -1; return false;
} }
aCodecCtx = pFormatCtx->streams[audioStream]->codec; aCodecCtx = pFormatCtx->streams[audioStream]->codec;
@ -183,12 +184,12 @@ ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs),
if (!aCodec) { if (!aCodec) {
ERROR("Unsupported audio codec!\n"); ERROR("Unsupported audio codec!\n");
return -1; return false;
} }
if (avcodec_open(aCodecCtx, aCodec)<0) { if (avcodec_open(aCodecCtx, aCodec)<0) {
ERROR("Could not open codec!\n"); ERROR("Could not open codec!\n");
return -1; return false;
} }
if (callback) { if (callback) {
@ -199,7 +200,7 @@ ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs),
ret = (*callback)( ptrs ); ret = (*callback)( ptrs );
} else } else
ret = 0; ret = true;
avcodec_close(aCodecCtx); avcodec_close(aCodecCtx);
av_close_input_file(pFormatCtx); av_close_input_file(pFormatCtx);
@ -210,16 +211,11 @@ ffmpeg_helper(struct input_stream *input, int (*callback)(BasePtrs *ptrs),
static bool static bool
ffmpeg_try_decode(struct input_stream *input) ffmpeg_try_decode(struct input_stream *input)
{ {
int ret; return input->seekable && ffmpeg_helper(input, NULL, NULL);
if (input->seekable) {
ret = ffmpeg_helper(input, NULL, NULL);
} else {
ret = 0;
}
return (ret == -1 ? 0 : 1);
} }
static int ffmpeg_decode_internal(BasePtrs *base) static bool
ffmpeg_decode_internal(BasePtrs *base)
{ {
struct decoder *decoder = base->decoder; struct decoder *decoder = base->decoder;
AVCodecContext *aCodecCtx = base->aCodecCtx; AVCodecContext *aCodecCtx = base->aCodecCtx;
@ -292,7 +288,7 @@ static int ffmpeg_decode_internal(BasePtrs *base)
} }
} while (decoder_get_command(decoder) != DECODE_COMMAND_STOP); } while (decoder_get_command(decoder) != DECODE_COMMAND_STOP);
return 0; return true;
} }
static bool static bool
@ -303,10 +299,10 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
base.input = input; base.input = input;
base.decoder = decoder; base.decoder = decoder;
return ffmpeg_helper(input, ffmpeg_decode_internal, &base) == 0; return ffmpeg_helper(input, ffmpeg_decode_internal, &base);
} }
static int ffmpeg_tag_internal(BasePtrs *base) static bool ffmpeg_tag_internal(BasePtrs *base)
{ {
struct tag *tag = (struct tag *) base->tag; struct tag *tag = (struct tag *) base->tag;
@ -315,7 +311,8 @@ static int ffmpeg_tag_internal(BasePtrs *base)
} else { } else {
tag->time = 0; tag->time = 0;
} }
return 0;
return true;
} }
//no tag reading in ffmpeg, check if playable //no tag reading in ffmpeg, check if playable
@ -323,7 +320,7 @@ static struct tag *ffmpeg_tag(char *file)
{ {
struct input_stream input; struct input_stream input;
BasePtrs base; BasePtrs base;
int ret; bool ret;
struct tag *tag = NULL; struct tag *tag = NULL;
if (!input_stream_open(&input, file)) { if (!input_stream_open(&input, file)) {
@ -335,9 +332,9 @@ static struct tag *ffmpeg_tag(char *file)
base.decoder = NULL; base.decoder = NULL;
base.tag = tag; base.tag = tag;
ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &base);
if (ret != 0) { ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &base);
if (ret) {
free(tag); free(tag);
tag = NULL; tag = NULL;
} }