Chromium Code Reviews| Index: media/mojo/services/media_type_converters.cc |
| diff --git a/media/mojo/services/media_type_converters.cc b/media/mojo/services/media_type_converters.cc |
| index 5f84a49a236287f00a61d4c7607745d9fc7cdbf9..3f5f66252f03e1f8de129b4a9357478cc85b24f8 100644 |
| --- a/media/mojo/services/media_type_converters.cc |
| +++ b/media/mojo/services/media_type_converters.cc |
| @@ -4,6 +4,7 @@ |
| #include "media/mojo/services/media_type_converters.h" |
| +#include "media/base/audio_buffer.h" |
| #include "media/base/audio_decoder_config.h" |
| #include "media/base/buffering_state.h" |
| #include "media/base/cdm_config.h" |
| @@ -13,6 +14,7 @@ |
| #include "media/base/demuxer_stream.h" |
| #include "media/base/media_keys.h" |
| #include "media/base/video_decoder_config.h" |
| +#include "media/base/video_frame.h" |
| #include "media/mojo/interfaces/demuxer_stream.mojom.h" |
| #include "mojo/converters/geometry/geometry_type_converters.h" |
| @@ -529,4 +531,123 @@ TypeConverter<media::CdmConfig, media::interfaces::CdmConfigPtr>::Convert( |
| return config; |
| } |
| +// static |
| +media::interfaces::AudioBufferPtr |
| +TypeConverter<media::interfaces::AudioBufferPtr, |
| + scoped_refptr<media::AudioBuffer>>:: |
| + Convert(const scoped_refptr<media::AudioBuffer>& input) { |
| + media::interfaces::AudioBufferPtr buffer( |
| + media::interfaces::AudioBuffer::New()); |
| + buffer->sample_format = |
| + static_cast<media::interfaces::SampleFormat>(input->sample_format_); |
| + buffer->channel_layout = |
| + static_cast<media::interfaces::ChannelLayout>(input->channel_layout()); |
| + buffer->channel_count = input->channel_count(); |
| + buffer->sample_rate = input->sample_rate(); |
| + buffer->frame_count = input->frame_count(); |
| + buffer->end_of_stream = input->end_of_stream(); |
| + buffer->timestamp_usec = input->timestamp().InMicroseconds(); |
| + // TODO(jrummell): Use a shared buffer rather than copying the data. |
|
xhwang
2015/11/23 22:22:18
We don't use shared memory for AudioBuffer yet. So
jrummell
2015/11/24 02:37:53
Done.
|
| + std::vector<uint8_t> input_data(input->data_.get(), |
|
xhwang
2015/11/23 22:22:18
how about EOS buffer?
jrummell
2015/11/24 02:37:53
EOSBuffer has 0 bytes, but we should avoid allocat
|
| + input->data_.get() + input->data_size_); |
| + buffer->data.Swap(&input_data); |
| + return buffer.Pass(); |
| +} |
| + |
| +// static |
| +scoped_refptr<media::AudioBuffer> |
| +TypeConverter<scoped_refptr<media::AudioBuffer>, |
| + media::interfaces::AudioBufferPtr>:: |
| + Convert(const media::interfaces::AudioBufferPtr& input) { |
| + if (input->end_of_stream) |
| + return media::AudioBuffer::CreateEOSBuffer(); |
| + |
| + // Setup channel pointers. AudioBuffer::CopyFrom() will only use the first |
| + // one in the case of interleaved data. |
| + std::vector<const uint8_t*> channel_ptrs(input->channel_count, nullptr); |
| + std::vector<uint8_t> storage = input->data.storage(); |
| + const int size_per_channel = storage.size() / input->channel_count; |
|
xhwang
2015/11/23 22:22:19
DCHECK that storage.size() % input->channel_count
jrummell
2015/11/24 02:37:53
Done.
|
| + for (int i = 0; i < input->channel_count; ++i) |
| + channel_ptrs[i] = vector_as_array(&storage) + i * size_per_channel; |
|
xhwang
2015/11/23 22:22:19
you can use storate.data() now:
https://chromium-
jrummell
2015/11/24 02:37:53
Done.
|
| + |
| + return media::AudioBuffer::CopyFrom( |
| + static_cast<media::SampleFormat>(input->sample_format), |
| + static_cast<media::ChannelLayout>(input->channel_layout), |
| + input->channel_count, input->sample_rate, input->frame_count, |
| + &channel_ptrs[0], |
| + base::TimeDelta::FromMicroseconds(input->timestamp_usec)); |
| +} |
| + |
| +// static |
| +media::interfaces::VideoFramePtr |
| +TypeConverter<media::interfaces::VideoFramePtr, |
| + scoped_refptr<media::VideoFrame>>:: |
| + Convert(const scoped_refptr<media::VideoFrame>& input) { |
| + media::interfaces::VideoFramePtr buffer(media::interfaces::VideoFrame::New()); |
| + buffer->end_of_stream = |
| + input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM); |
|
xhwang
2015/11/23 22:22:18
If it's a EOS frame, we probably don't need anythi
jrummell
2015/11/24 02:37:53
Done.
|
| + buffer->format = static_cast<media::interfaces::VideoFormat>(input->format()); |
| + buffer->width = input->coded_size().width(); |
| + buffer->height = input->coded_size().height(); |
| + buffer->visible_width = input->visible_rect().width(); |
| + buffer->visible_height = input->visible_rect().height(); |
| + buffer->natural_width = input->natural_size().width(); |
| + buffer->natural_height = input->natural_size().height(); |
| + buffer->timestamp_usec = input->timestamp().InMicroseconds(); |
| + |
| + if (buffer->width > 0 && buffer->height > 0) { |
| + // TODO(jrummell): Use a shared buffer rather than copying the data for |
| + // each plane. |
|
xhwang
2015/11/23 22:22:18
We probably will need to support both mode dependi
jrummell
2015/11/24 02:37:53
Agreed. Haven't figured out whether STORAGE_SHMEM
|
| + std::vector<uint8_t> y_data( |
| + input->data(media::VideoFrame::kYPlane), |
| + input->data(media::VideoFrame::kYPlane) + |
| + input->rows(media::VideoFrame::kYPlane) * |
| + input->stride(media::VideoFrame::kYPlane)); |
| + buffer->y_data.Swap(&y_data); |
| + |
| + std::vector<uint8_t> u_data( |
| + input->data(media::VideoFrame::kUPlane), |
| + input->data(media::VideoFrame::kUPlane) + |
| + input->rows(media::VideoFrame::kUPlane) * |
| + input->stride(media::VideoFrame::kUPlane)); |
| + buffer->u_data.Swap(&u_data); |
| + |
| + std::vector<uint8_t> v_data( |
| + input->data(media::VideoFrame::kVPlane), |
| + input->data(media::VideoFrame::kVPlane) + |
| + input->rows(media::VideoFrame::kVPlane) * |
| + input->stride(media::VideoFrame::kVPlane)); |
| + buffer->v_data.Swap(&v_data); |
| + } |
| + |
| + return buffer.Pass(); |
| +} |
| + |
| +// static |
| +scoped_refptr<media::VideoFrame> |
| +TypeConverter<scoped_refptr<media::VideoFrame>, |
| + media::interfaces::VideoFramePtr>:: |
| + Convert(const media::interfaces::VideoFramePtr& input) { |
| + if (input->end_of_stream) |
| + return media::VideoFrame::CreateEOSFrame(); |
| + |
| + scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( |
| + static_cast<media::VideoPixelFormat>(input->format), |
| + gfx::Size(input->width, input->height), |
| + gfx::Rect(input->visible_width, input->visible_height), |
| + gfx::Size(input->natural_width, input->natural_height), |
| + base::TimeDelta::FromMicroseconds(input->timestamp_usec)); |
| + memcpy(frame->data(media::VideoFrame::kYPlane), |
| + vector_as_array(&input->y_data.storage()), |
|
xhwang
2015/11/23 22:22:18
.data()
jrummell
2015/11/24 02:37:53
Done.
|
| + input->y_data.storage().size()); |
| + memcpy(frame->data(media::VideoFrame::kUPlane), |
| + vector_as_array(&input->u_data.storage()), |
| + input->u_data.storage().size()); |
| + memcpy(frame->data(media::VideoFrame::kVPlane), |
| + vector_as_array(&input->v_data.storage()), |
| + input->v_data.storage().size()); |
| + |
| + return frame.Pass(); |
| +} |
| + |
| } // namespace mojo |