From c2f64e4280e6b5463634b7ca2c71a083bffbe4b7 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Mon, 22 Mar 2010 18:22:39 +0100 Subject: [PATCH] Split metadata extraction out of scan_metadata_ffmpeg() --- src/filescanner_ffmpeg.c | 121 ++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/src/filescanner_ffmpeg.c b/src/filescanner_ffmpeg.c index aea04915..4c845946 100644 --- a/src/filescanner_ffmpeg.c +++ b/src/filescanner_ffmpeg.c @@ -118,20 +118,81 @@ static struct metadata_map md_map[] = }; +static int +extract_metadata(struct media_file_info *mfi, AVMetadata *md) +{ + AVMetadataTag *mdt; + char **strval; + uint32_t *intval; + char *endptr; + long tmpval; + int mdcount; + int i; + +#if 0 + /* Dump all the metadata reported by ffmpeg */ + mdt = NULL; + while ((mdt = av_metadata_get(md, "", mdt, AV_METADATA_IGNORE_SUFFIX)) != NULL) + fprintf(stderr, " -> %s = %s\n", mdt->key, mdt->value); +#endif + + mdcount = 0; + + /* Extract actual metadata */ + for (i = 0; md_map[i].key != NULL; i++) + { + mdt = av_metadata_get(md, md_map[i].key, NULL, 0); + if (mdt == NULL) + continue; + + if ((mdt->value == NULL) || (strlen(mdt->value) == 0)) + continue; + + mdcount++; + + if (!md_map[i].as_int) + { + strval = (char **) ((char *) mfi + md_map[i].offset); + + if (*strval == NULL) + *strval = strdup(mdt->value); + } + else + { + intval = (uint32_t *) ((char *) mfi + md_map[i].offset); + + if (*intval == 0) + { + errno = 0; + tmpval = strtol(mdt->value, &endptr, 10); + + if (((errno == ERANGE) && ((tmpval == LONG_MAX) || (tmpval == LONG_MIN))) + || ((errno != 0) && (tmpval == 0))) + continue; + + if (endptr == mdt->value) + continue; + + if (tmpval > UINT32_MAX) + continue; + + *intval = (uint32_t) tmpval; + } + } + } + + return mdcount; +} + int scan_metadata_ffmpeg(char *file, struct media_file_info *mfi) { AVFormatContext *ctx; - AVMetadataTag *mdt; enum CodecID codec_id; enum CodecID video_codec_id; enum CodecID audio_codec_id; int video_stream; int audio_stream; - char **strval; - uint32_t *intval; - char *endptr; - long tmpval; int mdcount; int i; int ret; @@ -348,55 +409,7 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi) goto skip_extract; } -#if 0 - /* Dump all the metadata reported by ffmpeg */ - mdt = NULL; - while ((mdt = av_metadata_get(ctx->metadata, "", mdt, AV_METADATA_IGNORE_SUFFIX)) != NULL) - fprintf(stderr, " -> %s = %s\n", mdt->key, mdt->value); -#endif - - /* Extract actual metadata */ - for (i = 0; md_map[i].key != NULL; i++) - { - mdt = av_metadata_get(ctx->metadata, md_map[i].key, NULL, 0); - if (mdt == NULL) - continue; - - if ((mdt->value == NULL) || (strlen(mdt->value) == 0)) - continue; - - mdcount++; - - if (!md_map[i].as_int) - { - strval = (char **) ((char *) mfi + md_map[i].offset); - - if (*strval == NULL) - *strval = strdup(mdt->value); - } - else - { - intval = (uint32_t *) ((char *) mfi + md_map[i].offset); - - if (*intval == 0) - { - errno = 0; - tmpval = strtol(mdt->value, &endptr, 10); - - if (((errno == ERANGE) && ((tmpval == LONG_MAX) || (tmpval == LONG_MIN))) - || ((errno != 0) && (tmpval == 0))) - continue; - - if (endptr == mdt->value) - continue; - - if (tmpval > UINT32_MAX) - continue; - - *intval = (uint32_t) tmpval; - } - } - } + mdcount += extract_metadata(mfi, ctx->metadata); /* fix up TV metadata */ if (mfi->media_kind == 10)