generic: make it parse ogg files
[platform/upstream/lightmediascanner.git] / src / plugins / generic / generic.c
index 4be6d60..387c02f 100644 (file)
@@ -49,16 +49,20 @@ static const struct lms_string_size _exts[] = {
     LMS_STATIC_STRING_SIZE(".m3u"),
     LMS_STATIC_STRING_SIZE(".mp4"),
     LMS_STATIC_STRING_SIZE(".wma"),
+    LMS_STATIC_STRING_SIZE(".ogg"),
 };
 
 DECL_STR(_codec_mpeg1layer3, "mpeg1layer3");
 DECL_STR(_container_3gp, "3gp");
 DECL_STR(_container_mp4, "mp4");
+DECL_STR(_container_ogg, "ogg");
 
 DECL_STR(_container_audio_wmav1, "wmav1");
 DECL_STR(_container_audio_wmav2, "wmav2");
 DECL_STR(_container_audio_wmavpro, "wmavpro");
 
+DECL_STR(_codec_video_theora, "theora");
+DECL_STR(_codec_audio_vorbis, "vorbis");
 DECL_STR(_codec_audio_asf, "asf");
 DECL_STR(_codec_audio_mpeg4aac_main, "mpeg4aac-main");
 DECL_STR(_codec_audio_mpeg4aac_lc, "mpeg4aac-lc");
@@ -85,6 +89,8 @@ static const struct codec_container_descriptor _codec_list[] = {
     {AV_CODEC_ID_WMAV1, &_codec_audio_asf},
     {AV_CODEC_ID_WMAV2, &_codec_audio_asf},
     {AV_CODEC_ID_WMAPRO, &_codec_audio_asf},
+    {AV_CODEC_ID_VORBIS, &_codec_audio_vorbis},
+    {AV_CODEC_ID_THEORA, &_codec_video_theora},
 };
 
 static const struct codec_container_descriptor _container_list[] = {
@@ -94,6 +100,8 @@ static const struct codec_container_descriptor _container_list[] = {
     {AV_CODEC_ID_WMAV2, &_container_audio_wmav2},
     {AV_CODEC_ID_WMAPRO, &_container_audio_wmavpro},
     {AV_CODEC_ID_H264, &_container_mp4},
+    {AV_CODEC_ID_VORBIS, &_container_ogg},
+    {AV_CODEC_ID_THEORA, &_container_ogg},
 };
 
 static void
@@ -163,7 +171,7 @@ _mp4_get_video_codec(AVStream *stream, struct lms_string_size *value)
     else
         snprintf(str_level, sizeof(str_level), "%u.%u", level / 10, level % 10);
 
-    ret.len = snprintf(buf, sizeof(buf), "h264-%s-l%s", str_profile, str_level);
+    ret.len = snprintf(buf, sizeof(buf), "h264-p%s-l%s", str_profile, str_level);
     ret.str = buf;
 
     lms_string_size_dup(value, &ret);
@@ -247,6 +255,16 @@ static const struct codec_container _codecs[] = {
         .get_container = NULL,
     },
     {
+        .id = AV_CODEC_ID_VORBIS,
+        .get_codec = _get_common_codec,
+        .get_container = _get_common_container,
+    },
+    {
+        .id = AV_CODEC_ID_THEORA,
+        .get_codec = _get_common_codec,
+        .get_container = _get_common_container,
+    },
+    {
         .id = AV_CODEC_ID_AAC,
         .get_codec = _mp4_get_audio_codec,
         .get_container = _get_common_container,
@@ -381,7 +399,11 @@ _parse_audio_stream(AVFormatContext *fmt_ctx, struct lms_audio_info *info, AVStr
     AVCodecContext *ctx = stream->codec;
 
     info->bitrate = ctx->bit_rate;
-    info->channels = av_get_channel_layout_nb_channels(ctx->channel_layout);
+    info->channels = ctx->channels;
+
+    if (!info->channels)
+        info->channels = av_get_channel_layout_nb_channels(ctx->channel_layout);
+
     info->sampling_rate = ctx->sample_rate;
     info->length = _get_stream_duration(fmt_ctx);
 
@@ -464,8 +486,7 @@ _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_in
     if (metadata)
         lms_string_size_strndup(&info.genre, metadata, -1);
 
-    av_opt_get_int(fmt_ctx, "ts_packetsize",
-                   AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ,
+    av_opt_get_int(fmt_ctx, "ts_packetsize", AV_OPT_SEARCH_CHILDREN,
                    &packet_size);
 
     language = _get_dict_value(fmt_ctx->metadata, "language");