| 1 | --- src/metadata/ffmpeg_handler.cc.orig 2010-03-25 07:58:10.000000000 -0700 |
| 2 | +++ src/metadata/ffmpeg_handler.cc 2013-01-10 16:04:04.000000000 -0800 |
| 3 | @@ -89,6 +89,33 @@ |
| 4 | |
| 5 | Ref<StringConverter> sc = StringConverter::m2i(); |
| 6 | |
| 7 | + /* Tabs are 4 characters here */ |
| 8 | + typedef struct {const char *avname; metadata_fields_t field;} mapping_t; |
| 9 | + static const mapping_t mapping[] = |
| 10 | + { |
| 11 | + {"title", M_TITLE}, |
| 12 | + {"artist", M_ARTIST}, |
| 13 | + {"album", M_ALBUM}, |
| 14 | + {"date", M_DATE}, |
| 15 | + {"genre", M_GENRE}, |
| 16 | + {"comment", M_DESCRIPTION}, |
| 17 | + {"track", M_TRACKNUMBER}, |
| 18 | + {NULL, M_MAX}, |
| 19 | + }; |
| 20 | + |
| 21 | + if (!pFormatCtx->metadata) |
| 22 | + return; |
| 23 | + for (const mapping_t *m = mapping; m->avname != NULL; m++) |
| 24 | + { |
| 25 | + AVDictionaryEntry *tag = NULL; |
| 26 | + tag = av_dict_get(pFormatCtx->metadata, m->avname, NULL, 0); |
| 27 | + if (tag && tag->value && tag->value[0]) |
| 28 | + { |
| 29 | + log_debug("Added metadata %s: %s\n", m->avname, tag->value); |
| 30 | + item->setMetadata(MT_KEYS[m->field].upnp, sc->convert(tag->value)); |
| 31 | + } |
| 32 | + } |
| 33 | + /* Old algorithm (doesn't work with libav >= 0.7) |
| 34 | if (strlen(pFormatCtx->title) > 0) |
| 35 | { |
| 36 | log_debug("Added metadata title: %s\n", pFormatCtx->title); |
| 37 | @@ -131,6 +158,7 @@ |
| 38 | item->setMetadata(MT_KEYS[M_TRACKNUMBER].upnp, |
| 39 | sc->convert(String::from(pFormatCtx->track))); |
| 40 | } |
| 41 | + */ |
| 42 | } |
| 43 | |
| 44 | // ffmpeg library calls |
| 45 | @@ -178,7 +206,7 @@ |
| 46 | for(i=0; i<pFormatCtx->nb_streams; i++) |
| 47 | { |
| 48 | AVStream *st = pFormatCtx->streams[i]; |
| 49 | - if((st != NULL) && (videoset == false) && (st->codec->codec_type == CODEC_TYPE_VIDEO)) |
| 50 | + if((st != NULL) && (videoset == false) && (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)) |
| 51 | { |
| 52 | if (st->codec->codec_tag > 0) |
| 53 | { |
| 54 | @@ -209,7 +237,7 @@ |
| 55 | *y = st->codec->height; |
| 56 | } |
| 57 | } |
| 58 | - if(st->codec->codec_type == CODEC_TYPE_AUDIO) |
| 59 | + if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) |
| 60 | { |
| 61 | // Increase number of audiochannels |
| 62 | audioch++; |
| 63 | @@ -260,14 +288,14 @@ |
| 64 | av_register_all(); |
| 65 | |
| 66 | // Open video file |
| 67 | - if (av_open_input_file(&pFormatCtx, |
| 68 | - item->getLocation().c_str(), NULL, 0, NULL) != 0) |
| 69 | + if (avformat_open_input(&pFormatCtx, |
| 70 | + item->getLocation().c_str(), NULL, NULL) != 0) |
| 71 | return; // Couldn't open file |
| 72 | |
| 73 | // Retrieve stream information |
| 74 | - if (av_find_stream_info(pFormatCtx) < 0) |
| 75 | + if (avformat_find_stream_info(pFormatCtx, NULL) < 0) |
| 76 | { |
| 77 | - av_close_input_file(pFormatCtx); |
| 78 | + avformat_close_input(&pFormatCtx); |
| 79 | return; // Couldn't find stream information |
| 80 | } |
| 81 | // Add metadata using ffmpeg library calls |
| 82 | @@ -276,7 +304,7 @@ |
| 83 | addFfmpegResourceFields(item, pFormatCtx, &x, &y); |
| 84 | |
| 85 | // Close the video file |
| 86 | - av_close_input_file(pFormatCtx); |
| 87 | + avformat_close_input(&pFormatCtx); |
| 88 | } |
| 89 | |
| 90 | Ref<IOHandler> FfmpegHandler::serveContent(Ref<CdsItem> item, int resNum, off_t *data_size) |