Bug 1304252 - Part 1: Provide error details for ffmpeg decoder. r=gerald, a=gchang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 21 Sep 2016 13:21:27 +1000
changeset 355730 70ffb93aff314ab94985ded54537ab356a93094b
parent 355729 4095b6940207fa34c95eae11f6d386af305a56d6
child 355731 b21c8cde69ce3ffe5931336d79d83b035c384765
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1304252
milestone51.0a2
Bug 1304252 - Part 1: Provide error details for ffmpeg decoder. r=gerald, a=gchang MozReview-Commit-ID: A0qbYNm4CjX
dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
@@ -122,74 +122,84 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(
 {
   AVPacket packet;
   mLib->av_init_packet(&packet);
 
   packet.data = const_cast<uint8_t*>(aSample->Data());
   packet.size = aSample->Size();
 
   if (!PrepareFrame()) {
-    NS_WARNING("FFmpeg audio decoder failed to allocate frame.");
-    return MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__);
+    return MediaResult(
+      NS_ERROR_OUT_OF_MEMORY,
+      RESULT_DETAIL("FFmpeg audio decoder failed to allocate frame"));
   }
 
   int64_t samplePosition = aSample->mOffset;
   media::TimeUnit pts = media::TimeUnit::FromMicroseconds(aSample->mTime);
 
   while (packet.size > 0) {
     int decoded;
     int bytesConsumed =
       mLib->avcodec_decode_audio4(mCodecContext, mFrame, &decoded, &packet);
 
     if (bytesConsumed < 0) {
       NS_WARNING("FFmpeg audio decoder error.");
-      return NS_ERROR_DOM_MEDIA_DECODE_ERR;
+      return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR,
+                         RESULT_DETAIL("FFmpeg audio error:%d", bytesConsumed));
     }
 
     if (mFrame->format != AV_SAMPLE_FMT_FLT &&
         mFrame->format != AV_SAMPLE_FMT_FLTP &&
         mFrame->format != AV_SAMPLE_FMT_S16 &&
         mFrame->format != AV_SAMPLE_FMT_S16P &&
         mFrame->format != AV_SAMPLE_FMT_S32 &&
         mFrame->format != AV_SAMPLE_FMT_S32P) {
-      NS_WARNING("FFmpeg audio decoder outputs unsupported audio format.");
-      return NS_ERROR_DOM_MEDIA_DECODE_ERR;
+      return MediaResult(
+        NS_ERROR_DOM_MEDIA_DECODE_ERR,
+        RESULT_DETAIL("FFmpeg audio decoder outputs unsupported audio format"));
     }
 
     if (decoded) {
       uint32_t numChannels = mCodecContext->channels;
       AudioConfig::ChannelLayout layout(numChannels);
       if (!layout.IsValid()) {
-        return NS_ERROR_DOM_MEDIA_FATAL_ERR;
+        return MediaResult(
+          NS_ERROR_DOM_MEDIA_FATAL_ERR,
+          RESULT_DETAIL("Unsupported channel layout:%u", numChannels));
       }
 
       uint32_t samplingRate = mCodecContext->sample_rate;
 
       AlignedAudioBuffer audio =
         CopyAndPackAudio(mFrame, numChannels, mFrame->nb_samples);
+      if (!audio) {
+        return MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__);
+      }
 
       media::TimeUnit duration =
         FramesToTimeUnit(mFrame->nb_samples, samplingRate);
-      if (!audio || !duration.IsValid()) {
-        NS_WARNING("Invalid count of accumulated audio samples");
-        return NS_ERROR_DOM_MEDIA_OVERFLOW_ERR;
+      if (!duration.IsValid()) {
+        return MediaResult(
+          NS_ERROR_DOM_MEDIA_OVERFLOW_ERR,
+          RESULT_DETAIL("Invalid sample duration"));
       }
 
       RefPtr<AudioData> data = new AudioData(samplePosition,
                                              pts.ToMicroseconds(),
                                              duration.ToMicroseconds(),
                                              mFrame->nb_samples,
                                              Move(audio),
                                              numChannels,
                                              samplingRate);
       mCallback->Output(data);
       pts += duration;
       if (!pts.IsValid()) {
-        NS_WARNING("Invalid count of accumulated audio samples");
-        return NS_ERROR_DOM_MEDIA_OVERFLOW_ERR;
+        return MediaResult(
+          NS_ERROR_DOM_MEDIA_OVERFLOW_ERR,
+          RESULT_DETAIL("Invalid count of accumulated audio samples"));
       }
     }
     packet.data += bytesConsumed;
     packet.size -= bytesConsumed;
     samplePosition += bytesConsumed;
   }
   return NS_OK;
 }
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -245,18 +245,18 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(
 
   FFMPEG_LOG("DoDecodeFrame:decode_video: rv=%d decoded=%d "
              "(Input: pts(%lld) dts(%lld) Output: pts(%lld) "
              "opaque(%lld) pkt_pts(%lld) pkt_dts(%lld))",
              bytesConsumed, decoded, packet.pts, packet.dts, mFrame->pts,
              mFrame->reordered_opaque, mFrame->pkt_pts, mFrame->pkt_dts);
 
   if (bytesConsumed < 0) {
-    NS_WARNING("FFmpeg video decoder error.");
-    return NS_ERROR_DOM_MEDIA_DECODE_ERR;
+    return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR,
+                       RESULT_DETAIL("FFmpeg video error:%d", bytesConsumed));
   }
 
   if (!decoded) {
     if (aGotFrame) {
       *aGotFrame = false;
     }
     return NS_OK;
   }
@@ -310,18 +310,18 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(
                                   duration,
                                   b,
                                   !!mFrame->key_frame,
                                   -1,
                                   mInfo.ScaledImageRect(mFrame->width,
                                                         mFrame->height));
 
   if (!v) {
-    NS_WARNING("image allocation error.");
-    return MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__);
+    return MediaResult(NS_ERROR_OUT_OF_MEMORY,
+                       RESULT_DETAIL("image allocation error"));
   }
   mCallback->Output(v);
   if (aGotFrame) {
     *aGotFrame = true;
   }
   return NS_OK;
 }