Bug 1568058 - pt 2 - Add batch decode methods to MediaDataDecoder. r=jya
authorMichael Froman <mfroman@mozilla.com>
Thu, 14 Nov 2019 16:06:39 +0000
changeset 502086 08c7f0dd63c8f09cd5c3f678920c9b89622637bc
parent 502085 ff0b20be880be24af649b8b776608a2672346615
child 502087 53a35e1379d64cb80fe1df622afb9aa8020dbcf1
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1568058, 1590475
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1568058 - pt 2 - Add batch decode methods to MediaDataDecoder. r=jya In order to use the batch decoding abilities added in Bug 1590475, we need to also add batch decoding to MediaDataDecoder. For now only RemoteMediaDataDecoder (and AudioTrimmer as a wrapper) know how to do batch, but this could be implemented more generically later in MediaDataDecoder. Differential Revision: https://phabricator.services.mozilla.com/D51452
dom/media/ipc/RemoteMediaDataDecoder.cpp
dom/media/ipc/RemoteMediaDataDecoder.h
dom/media/platforms/PlatformDecoderModule.h
dom/media/platforms/wrappers/AudioTrimmer.h
--- a/dom/media/ipc/RemoteMediaDataDecoder.cpp
+++ b/dom/media/ipc/RemoteMediaDataDecoder.cpp
@@ -54,16 +54,25 @@ RefPtr<MediaDataDecoder::DecodePromise> 
   RefPtr<MediaRawData> sample = aSample;
   return InvokeAsync(
       RemoteDecoderManagerChild::GetManagerAbstractThread(), __func__,
       [self, sample]() {
         return self->mChild->Decode(nsTArray<RefPtr<MediaRawData>>{sample});
       });
 }
 
+RefPtr<MediaDataDecoder::DecodePromise> RemoteMediaDataDecoder::DecodeBatch(
+    nsTArray<RefPtr<MediaRawData>>&& aSamples) {
+  RefPtr<RemoteMediaDataDecoder> self = this;
+  return InvokeAsync(RemoteDecoderManagerChild::GetManagerAbstractThread(),
+                     __func__, [self, samples = std::move(aSamples)]() {
+                       return self->mChild->Decode(samples);
+                     });
+}
+
 RefPtr<MediaDataDecoder::FlushPromise> RemoteMediaDataDecoder::Flush() {
   RefPtr<RemoteMediaDataDecoder> self = this;
   return InvokeAsync(RemoteDecoderManagerChild::GetManagerAbstractThread(),
                      __func__, [self]() { return self->mChild->Flush(); });
 }
 
 RefPtr<MediaDataDecoder::DecodePromise> RemoteMediaDataDecoder::Drain() {
   RefPtr<RemoteMediaDataDecoder> self = this;
--- a/dom/media/ipc/RemoteMediaDataDecoder.h
+++ b/dom/media/ipc/RemoteMediaDataDecoder.h
@@ -28,16 +28,19 @@ class RemoteMediaDataDecoder
       public DecoderDoctorLifeLogger<RemoteMediaDataDecoder> {
  public:
   friend class GpuDecoderModule;
   friend class RemoteDecoderModule;
 
   // MediaDataDecoder
   RefPtr<InitPromise> Init() override;
   RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
+  bool CanDecodeBatch() override { return true; }
+  RefPtr<DecodePromise> DecodeBatch(
+      nsTArray<RefPtr<MediaRawData>>&& aSamples) override;
   RefPtr<DecodePromise> Drain() override;
   RefPtr<FlushPromise> Flush() override;
   RefPtr<ShutdownPromise> Shutdown() override;
   bool IsHardwareAccelerated(nsACString& aFailureReason) const override;
   void SetSeekThreshold(const media::TimeUnit& aTime) override;
   nsCString GetDescriptionName() const override;
   ConversionRequired NeedsConversion() const override;
 
--- a/dom/media/platforms/PlatformDecoderModule.h
+++ b/dom/media/platforms/PlatformDecoderModule.h
@@ -283,16 +283,33 @@ class MediaDataDecoder : public DecoderD
   virtual RefPtr<InitPromise> Init() = 0;
 
   // Inserts a sample into the decoder's decode pipeline. The DecodePromise will
   // be resolved with the decoded MediaData. In case the decoder needs more
   // input, the DecodePromise may be resolved with an empty array of samples to
   // indicate that Decode should be called again before a MediaData is returned.
   virtual RefPtr<DecodePromise> Decode(MediaRawData* aSample) = 0;
 
+  // This could probably be implemented as a wrapper that takes a
+  // generic MediaDataDecoder and manages batching as needed.  For now
+  // only AudioTrimmer with RemoteMediaDataDecoder supports batch
+  // decoding.
+  // Inserts an array of samples into the decoder's decode pipeline. The
+  // DecodePromise will be resolved with the decoded MediaData. In case
+  // the decoder needs more input, the DecodePromise may be resolved
+  // with an empty array of samples to indicate that Decode should be
+  // called again before a MediaData is returned.
+  virtual bool CanDecodeBatch() { return false; }
+  virtual RefPtr<DecodePromise> DecodeBatch(
+      nsTArray<RefPtr<MediaRawData>>&& aSamples) {
+    MOZ_CRASH("DecodeBatch not implemented yet");
+    return MediaDataDecoder::DecodePromise::CreateAndReject(
+        NS_ERROR_DOM_MEDIA_DECODE_ERR, __func__);
+  }
+
   // Causes all complete samples in the pipeline that can be decoded to be
   // output. If the decoder can't produce samples from the current output,
   // it drops the input samples. The decoder may be holding onto samples
   // that are required to decode samples that it expects to get in future.
   // This is called when the demuxer reaches end of stream.
   // This function is asynchronous.
   // The MediaDataDecoder shall resolve the pending DecodePromise with drained
   // samples. Drain will be called multiple times until the resolved
--- a/dom/media/platforms/wrappers/AudioTrimmer.h
+++ b/dom/media/platforms/wrappers/AudioTrimmer.h
@@ -17,16 +17,21 @@ DDLoggedTypeDeclNameAndBase(AudioTrimmer
 class AudioTrimmer : public MediaDataDecoder {
  public:
   AudioTrimmer(already_AddRefed<MediaDataDecoder> aDecoder,
                const CreateDecoderParams& aParams)
       : mDecoder(aDecoder), mTaskQueue(aParams.mTaskQueue) {}
 
   RefPtr<InitPromise> Init() override;
   RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
+  bool CanDecodeBatch() override { return mDecoder->CanDecodeBatch(); }
+  RefPtr<DecodePromise> DecodeBatch(
+      nsTArray<RefPtr<MediaRawData>>&& aSamples) override {
+    return mDecoder->DecodeBatch(std::move(aSamples));
+  }
   RefPtr<DecodePromise> Drain() override;
   RefPtr<FlushPromise> Flush() override;
   RefPtr<ShutdownPromise> Shutdown() override;
   nsCString GetDescriptionName() const override;
   bool IsHardwareAccelerated(nsACString& aFailureReason) const override;
   void SetSeekThreshold(const media::TimeUnit& aTime) override;
   bool SupportDecoderRecycling() const override;
   ConversionRequired NeedsConversion() const override;