Bug 1304252: P1. Provide error details for ffmpeg decoder. r?gerald
MozReview-Commit-ID: A0qbYNm4CjX
--- 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;
}