Commit b25fac81 authored by John Lin's avatar John Lin Committed by Pier Angelo Vendrame
Browse files

Bug 2023515 - p2: use SampleBuffer native copy method. a=diannaS DONTBUILD

parent bc9072b5
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -253,9 +253,10 @@ static RefPtr<MediaByteBuffer> ExtractCodecConfig(
    const int32_t aSize, const bool aAsAVCC) {
  auto config = MakeRefPtr<MediaByteBuffer>(aSize);
  config->SetLength(aSize);
  jni::ByteBuffer::LocalRef dest =
      jni::ByteBuffer::New(config->Elements(), aSize);
  aBuffer->WriteToByteBuffer(dest, aOffset, aSize);
  NS_ENSURE_SUCCESS(
      aBuffer->NativeCopy(reinterpret_cast<jlong>(config->Elements()), aOffset,
                          aSize),
      nullptr);
  if (!aAsAVCC) {
    return config;
  }
@@ -359,8 +360,9 @@ RefPtr<MediaRawData> AndroidDataEncoder::GetOutputData(
    return nullptr;
  }

  jni::ByteBuffer::LocalRef buf = jni::ByteBuffer::New(writer->Data(), aSize);
  aBuffer->WriteToByteBuffer(buf, aOffset, aSize);
  NS_ENSURE_SUCCESS(aBuffer->NativeCopy(reinterpret_cast<jlong>(writer->Data()),
                                        aOffset, aSize),
                    nullptr);
  output->mKeyframe = aIsKeyFrame;

  return output;
@@ -393,9 +395,10 @@ RefPtr<MediaRawData> AndroidDataEncoder::GetOutputDataH264(
    PodCopy(writer->Data(), mConfigData->Elements(), prependSize);
  }

  jni::ByteBuffer::LocalRef buf =
      jni::ByteBuffer::New(writer->Data() + prependSize, aSize);
  aBuffer->WriteToByteBuffer(buf, aOffset, aSize);
  NS_ENSURE_SUCCESS(
      aBuffer->NativeCopy(reinterpret_cast<jlong>(writer->Data() + prependSize),
                          aOffset, aSize),
      nullptr);

  if (asAVCC && !AnnexB::ConvertSampleToAVCC(output, avccHeader)) {
    AND_ENC_LOGE("fail to convert annex-b sample to AVCC");
+7 −2
Original line number Diff line number Diff line
@@ -812,8 +812,13 @@ class RemoteAudioDecoder final : public RemoteDataDecoder {
        LOG("OOM while allocating temporary output buffer");
        return;
      }
      jni::ByteBuffer::LocalRef dest = jni::ByteBuffer::New(audio.get(), size);
      aBuffer->WriteToByteBuffer(dest, offset, size);
      nsresult rv = aBuffer->NativeCopy(reinterpret_cast<jlong>(audio.get()),
                                        offset, size);
      if (NS_FAILED(rv)) {
        LOG("Fail to copy audio buffer");
        Error(MediaResult(rv, __func__));
        return;
      }
      AlignedFloatBuffer converted = audio.Inflate();

      TimeUnit pts = TimeUnit::FromMicroseconds(presentationTimeUs);