| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |
| 6 #define MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "media/base/demuxer_stream.h" |
| 13 #include "media/mojo/interfaces/media_types.mojom.h" |
| 14 #include "mojo/public/cpp/system/data_pipe.h" |
| 15 |
| 16 namespace media { |
| 17 |
| 18 class DecoderBuffer; |
| 19 |
| 20 // A helper class that converts mojom::DecoderBuffer to media::DecoderBuffer. |
| 21 // The data part of the DecoderBuffer is read from a DataPipe. |
| 22 class MojoDecoderBufferReader { |
| 23 public: |
| 24 // Creates a MojoDecoderBufferReader of |type| and set the |producer_handle|. |
| 25 static std::unique_ptr<MojoDecoderBufferReader> Create( |
| 26 DemuxerStream::Type type, |
| 27 mojo::ScopedDataPipeProducerHandle* producer_handle); |
| 28 |
| 29 // Hold the consumer handle to read DecoderBuffer data. |
| 30 explicit MojoDecoderBufferReader( |
| 31 mojo::ScopedDataPipeConsumerHandle consumer_handle); |
| 32 |
| 33 ~MojoDecoderBufferReader(); |
| 34 |
| 35 // Converts |buffer| into a DecoderBuffer (read data from DataPipe if needed). |
| 36 // Returns the result DecoderBuffer. Returns null in case of an error. |
| 37 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
| 38 const mojom::DecoderBufferPtr& buffer); |
| 39 |
| 40 private: |
| 41 // For reading the data section of a DecoderBuffer. |
| 42 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(MojoDecoderBufferReader); |
| 45 }; |
| 46 |
| 47 // A helper class that converts media::DecoderBuffer to mojom::DecoderBuffer. |
| 48 // The data part of the DecoderBuffer is written into a DataPipe. |
| 49 class MojoDecoderBufferWriter { |
| 50 public: |
| 51 // Creates a MojoDecoderBufferWriter of |type| and set the |consumer_handle|. |
| 52 static std::unique_ptr<MojoDecoderBufferWriter> Create( |
| 53 DemuxerStream::Type type, |
| 54 mojo::ScopedDataPipeConsumerHandle* consumer_handle); |
| 55 |
| 56 // Hold the producer handle to write DecoderBuffer data. |
| 57 explicit MojoDecoderBufferWriter( |
| 58 mojo::ScopedDataPipeProducerHandle producer_handle); |
| 59 |
| 60 ~MojoDecoderBufferWriter(); |
| 61 |
| 62 // Converts a DecoderBuffer into mojo DecoderBuffer, writing data into |
| 63 // DataPipe if needed. Returns null if conversion failed. |
| 64 mojom::DecoderBufferPtr WriteDecoderBuffer( |
| 65 const scoped_refptr<DecoderBuffer>& media_buffer); |
| 66 |
| 67 private: |
| 68 // For writing the data section of DecoderBuffer into DataPipe. |
| 69 mojo::ScopedDataPipeProducerHandle producer_handle_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(MojoDecoderBufferWriter); |
| 72 }; |
| 73 |
| 74 } // namespace media |
| 75 |
| 76 #endif // MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |
| OLD | NEW |