Verified Commit 81ad8910 authored by Timothy Nikkel's avatar Timothy Nikkel Committed by ma1
Browse files

Bug 2045624. a=RyanVM DONTBUILD

parent b8db7029
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -613,15 +613,14 @@ class Dav1dDecoder final : AVIFDecoderInterface {
    return 0;
  }

  static Dav1dResult GetPicture(Dav1dContext& aContext,
                                const MediaRawData& aBytes,
  static Dav1dResult GetPicture(Dav1dContext& aContext, MediaRawData& aBytes,
                                Dav1dPicture* aPicture,
                                bool aShouldSendTelemetry) {
    MOZ_ASSERT(aPicture);

    Dav1dData dav1dData;
    Dav1dResult r = dav1d_data_wrap(&dav1dData, aBytes.Data(), aBytes.Size(),
                                    Dav1dFreeCallback_s, nullptr);
                                    Dav1dFreeCallback_s, &aBytes);

    MOZ_LOG(
        sAVIFLog, r == 0 ? LogLevel::Verbose : LogLevel::Error,
@@ -631,12 +630,22 @@ class Dav1dDecoder final : AVIFDecoderInterface {
      return r;
    }

    // After a successful dav1d_data_wrap call, dav1d effectively owns a
    // reference to the buffer that aBytes holds until dav1d calls the passed in
    // free callback Dav1dFreeCallback_s. We handle this with an AddRef here and
    // a Release in Dav1dFreeCallback_s.
    aBytes.AddRef();

    r = dav1d_send_data(&aContext, &dav1dData);

    MOZ_LOG(sAVIFLog, r == 0 ? LogLevel::Debug : LogLevel::Error,
            ("dav1d_send_data -> %d", r));

    if (r != 0) {
      // On failure dav1d leaves the caller's reference to the data intact;
      // drop it (this invokes Dav1dFreeCallback_s once dav1d holds no other
      // references).
      dav1d_data_unref(&dav1dData);
      return r;
    }

@@ -660,10 +669,9 @@ class Dav1dDecoder final : AVIFDecoderInterface {
    return r;
  }

  // A dummy callback for dav1d_data_wrap
  static void Dav1dFreeCallback_s(const uint8_t* aBuf, void* aCookie) {
    // The buf is managed by the mParser inside Dav1dDecoder itself. Do
    // nothing here.
    MOZ_ASSERT(aCookie);
    static_cast<MediaRawData*>(aCookie)->Release();
  }

  static UniquePtr<AVIFDecodedData> Dav1dPictureToDecodedData(