Verified Commit 43601439 authored by John Lin's avatar John Lin Committed by ma1
Browse files

Bug 2030198 - report error when fails to copy Android encoder output data. a=diannaS DONTBUILD

Besides reporting error, drain state should also be updated and promise should be rejected when needed.

Original Revision: https://phabricator.services.mozilla.com/D293708

Differential Revision: https://phabricator.services.mozilla.com/D294459
parent cf906219
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -303,7 +303,11 @@ void AndroidDataEncoder::ProcessOutput(

  int32_t flags;
  bool ok = NS_SUCCEEDED(info->Flags(&flags));
  bool isEOS = !!(flags & java::sdk::MediaCodec::BUFFER_FLAG_END_OF_STREAM);
  bool isEOS =
      ok && !!(flags & java::sdk::MediaCodec::BUFFER_FLAG_END_OF_STREAM);
  if (isEOS) {
    mDrainState = DrainState::DRAINED;
  }

  int32_t offset;
  ok &= NS_SUCCEEDED(info->Offset(&offset));
@@ -315,6 +319,8 @@ void AndroidDataEncoder::ProcessOutput(
  ok &= NS_SUCCEEDED(info->PresentationTimeUs(&presentationTimeUs));

  if (!ok) {
    Error(MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                      "fail to get output buffer info"_ns));
    return;
  }

@@ -334,15 +340,17 @@ void AndroidDataEncoder::ProcessOutput(
          aBuffer, offset, size,
          !!(flags & java::sdk::MediaCodec::BUFFER_FLAG_KEY_FRAME));
    }
    if (!output) {
      Error(MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                        "fail to copy sample buffer"_ns));
      return;
    }
    output->mEOS = isEOS;
    output->mTime = media::TimeUnit::FromMicroseconds(presentationTimeUs);
    output->mDuration = mInputSampleDuration;
    mEncodedData.AppendElement(std::move(output));
  }

  if (isEOS) {
    mDrainState = DrainState::DRAINED;
  }
  if (!mDrainPromise.IsEmpty()) {
    EncodedData pending = std::move(mEncodedData);
    mDrainPromise.Resolve(std::move(pending), __func__);
@@ -356,7 +364,7 @@ RefPtr<MediaRawData> AndroidDataEncoder::GetOutputData(
  auto output = MakeRefPtr<MediaRawData>();
  UniquePtr<MediaRawDataWriter> writer(output->CreateWriter());
  if (!writer->SetSize(aSize)) {
    AND_ENC_LOGE("fail to allocate output buffer");
    AND_ENC_LOGE("fail to allocate output buffer: size=%d", aSize);
    return nullptr;
  }

@@ -486,6 +494,9 @@ void AndroidDataEncoder::Error(const MediaResult& aError) {
  AssertOnTaskQueue();

  mError = Some(aError);
  if (!mDrainPromise.IsEmpty()) {
    mDrainPromise.Reject(aError, __func__);
  }
}

void AndroidDataEncoder::CallbacksSupport::HandleInput(int64_t aTimestamp,