Chromium Code Reviews| Index: media/mojo/common/mojo_decoder_buffer_converter.h |
| diff --git a/media/mojo/common/mojo_decoder_buffer_converter.h b/media/mojo/common/mojo_decoder_buffer_converter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cede467249398308a51998d45830e54360b3d7a7 |
| --- /dev/null |
| +++ b/media/mojo/common/mojo_decoder_buffer_converter.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |
|
alokp
2016/06/27 20:18:21
nit: Since this file contains implementations of R
xhwang
2016/06/28 01:11:48
I still like converter better (the same reason why
|
| +#define MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |
| + |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "media/base/demuxer_stream.h" |
| +#include "media/mojo/interfaces/media_types.mojom.h" |
| +#include "mojo/public/cpp/system/data_pipe.h" |
| + |
| +namespace media { |
| + |
| +class DecoderBuffer; |
| + |
| +// A helper class that converts mojom::DecoderBuffer to media::DecoderBuffer. |
| +// The data part of the DecoderBuffer is read from a DataPipe. |
| +class MojoDecoderBufferReader { |
| + public: |
| + // Creates a MojoDecoderBufferReader of |type| and set the |producer_handle|. |
| + static std::unique_ptr<MojoDecoderBufferReader> Create( |
| + DemuxerStream::Type type, |
| + mojo::ScopedDataPipeProducerHandle* producer_handle); |
| + |
| + // Hold the consumer handle to read DecoderBuffer data. |
| + explicit MojoDecoderBufferReader( |
| + mojo::ScopedDataPipeConsumerHandle consumer_handle); |
| + |
| + ~MojoDecoderBufferReader(); |
| + |
| + // Converts |buffer| into a DecoderBuffer (read data from DataPipe if needed). |
|
alokp
2016/06/27 20:18:21
nit: Change "Converts" to "Reads decoder buffer da
xhwang
2016/06/28 01:11:48
See comment above. This function not only read the
|
| + // Returns the result DecoderBuffer. Returns null in case of an error. |
| + scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
| + const mojom::DecoderBufferPtr& buffer); |
| + |
| + private: |
| + // For reading the data section of a DecoderBuffer. |
| + mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MojoDecoderBufferReader); |
| +}; |
| + |
| +// A helper class that converts media::DecoderBuffer to mojom::DecoderBuffer. |
| +// The data part of the DecoderBuffer is written into a DataPipe. |
| +class MojoDecoderBufferWriter { |
| + public: |
| + // Creates a MojoDecoderBufferWriter of |type| and set the |consumer_handle|. |
| + static std::unique_ptr<MojoDecoderBufferWriter> Create( |
| + DemuxerStream::Type type, |
| + mojo::ScopedDataPipeConsumerHandle* consumer_handle); |
| + |
| + // Hold the producer handle to write DecoderBuffer data. |
| + explicit MojoDecoderBufferWriter( |
| + mojo::ScopedDataPipeProducerHandle producer_handle); |
| + |
| + ~MojoDecoderBufferWriter(); |
| + |
| + // Converts a DecoderBuffer into mojo DecoderBuffer, writing data into |
| + // DataPipe if needed. Returns null if conversion failed. |
| + mojom::DecoderBufferPtr WriteDecoderBuffer( |
| + const scoped_refptr<DecoderBuffer>& media_buffer); |
| + |
| + private: |
| + // For writing the data section of DecoderBuffer into DataPipe. |
| + mojo::ScopedDataPipeProducerHandle producer_handle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MojoDecoderBufferWriter); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_MOJO_COMMON_MOJO_DECODER_BUFFER_CONVERTER_ |