OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h" | 5 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chromecast/media/base/decrypt_context.h" | 19 #include "chromecast/media/cma/base/cast_decoder_buffer_impl.h" |
20 #include "chromecast/media/cma/backend/audio_pipeline_device.h" | |
21 #include "chromecast/media/cma/backend/media_clock_device.h" | |
22 #include "chromecast/media/cma/backend/media_pipeline_device.h" | |
23 #include "chromecast/media/cma/backend/video_pipeline_device.h" | |
24 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" | 20 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" |
25 #include "chromecast/media/cma/base/decoder_buffer_base.h" | 21 #include "chromecast/media/cma/pipeline/frame_status_cb_impl.h" |
| 22 #include "chromecast/media/cma/pipeline/media_component_device_client_impl.h" |
26 #include "chromecast/media/cma/test/frame_segmenter_for_test.h" | 23 #include "chromecast/media/cma/test/frame_segmenter_for_test.h" |
| 24 #include "chromecast/public/media/audio_pipeline_device.h" |
| 25 #include "chromecast/public/media/cast_decoder_buffer.h" |
| 26 #include "chromecast/public/media/decrypt_context.h" |
| 27 #include "chromecast/public/media/media_clock_device.h" |
| 28 #include "chromecast/public/media/video_pipeline_device.h" |
27 #include "media/base/audio_decoder_config.h" | 29 #include "media/base/audio_decoder_config.h" |
28 #include "media/base/buffers.h" | 30 #include "media/base/buffers.h" |
29 #include "media/base/decoder_buffer.h" | 31 #include "media/base/decoder_buffer.h" |
30 #include "media/base/video_decoder_config.h" | 32 #include "media/base/video_decoder_config.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
32 | 34 |
33 namespace chromecast { | 35 namespace chromecast { |
34 namespace media { | 36 namespace media { |
35 | 37 |
36 MediaComponentDeviceFeederForTest::MediaComponentDeviceFeederForTest( | 38 MediaComponentDeviceFeederForTest::MediaComponentDeviceFeederForTest( |
37 MediaComponentDevice *device, | 39 MediaComponentDevice *device, |
38 const BufferList& frames) | 40 const BufferList& frames) |
39 : media_component_device_(device), | 41 : media_component_device_(device), |
40 rendering_frame_idx_(1), | 42 rendering_frame_idx_(1), |
41 clock_frame_idx_(1), | 43 clock_frame_idx_(1), |
42 feeding_completed_(false) { | 44 feeding_completed_(false) { |
43 frames_ = frames; | 45 frames_ = frames; |
44 } | 46 } |
45 | 47 |
46 MediaComponentDeviceFeederForTest::~MediaComponentDeviceFeederForTest() { | 48 MediaComponentDeviceFeederForTest::~MediaComponentDeviceFeederForTest() { |
47 } | 49 } |
48 | 50 |
49 void MediaComponentDeviceFeederForTest::Initialize( | 51 void MediaComponentDeviceFeederForTest::Initialize( |
50 const base::Closure& eos_cb) { | 52 const base::Closure& eos_cb) { |
51 eos_cb_ = eos_cb; | 53 eos_cb_ = eos_cb; |
52 | 54 |
53 MediaComponentDevice::Client client; | 55 media_component_device_->SetClient( |
54 client.eos_cb = | 56 new MediaComponentDeviceClientImpl(base::Bind( |
55 base::Bind(&MediaComponentDeviceFeederForTest::OnEos, | 57 &MediaComponentDeviceFeederForTest::OnEos, base::Unretained(this)))); |
56 base::Unretained(this)); | |
57 media_component_device_->SetClient(client); | |
58 | 58 |
59 bool success = | 59 bool success = |
60 media_component_device_->SetState(MediaComponentDevice::kStateIdle); | 60 media_component_device_->SetState(MediaComponentDevice::kStateIdle); |
61 ASSERT_TRUE(success); | 61 ASSERT_TRUE(success); |
62 success = media_component_device_->SetStartPts(base::TimeDelta()); | 62 success = media_component_device_->SetStartPts(0); |
63 ASSERT_TRUE(success); | 63 ASSERT_TRUE(success); |
64 success = | 64 success = |
65 media_component_device_->SetState(MediaComponentDevice::kStatePaused); | 65 media_component_device_->SetState(MediaComponentDevice::kStatePaused); |
66 ASSERT_TRUE(success); | 66 ASSERT_TRUE(success); |
67 } | 67 } |
68 | 68 |
69 void MediaComponentDeviceFeederForTest::Feed() { | 69 void MediaComponentDeviceFeederForTest::Feed() { |
70 // Start rendering if needed. | 70 // Start rendering if needed. |
71 if (rendering_frame_idx_ == 0) { | 71 if (rendering_frame_idx_ == 0) { |
72 media_component_device_->SetState(MediaComponentDevice::kStateRunning); | 72 media_component_device_->SetState(MediaComponentDevice::kStateRunning); |
73 } else { | 73 } else { |
74 rendering_frame_idx_--; | 74 rendering_frame_idx_--; |
75 } | 75 } |
76 | 76 |
77 // Possibly feed one frame | 77 // Possibly feed one frame |
78 DCHECK(!frames_.empty()); | 78 DCHECK(!frames_.empty()); |
79 scoped_refptr<DecoderBufferBase> buffer = frames_.front(); | 79 scoped_refptr<DecoderBufferBase> buffer = frames_.front(); |
80 | 80 |
81 MediaComponentDevice::FrameStatus status = | 81 MediaComponentDevice::FrameStatus status = media_component_device_->PushFrame( |
82 media_component_device_->PushFrame( | 82 nullptr, // decrypt_context |
83 scoped_refptr<DecryptContext>(), | 83 new CastDecoderBufferImpl(buffer), |
84 buffer, | 84 new FrameStatusCBImpl( |
85 base::Bind(&MediaComponentDeviceFeederForTest::OnFramePushed, | 85 base::Bind(&MediaComponentDeviceFeederForTest::OnFramePushed, |
86 base::Unretained(this))); | 86 base::Unretained(this)))); |
87 EXPECT_NE(status, MediaComponentDevice::kFrameFailed); | 87 EXPECT_NE(status, MediaComponentDevice::kFrameFailed); |
88 frames_.pop_front(); | 88 frames_.pop_front(); |
89 | 89 |
90 // Feeding is done, just wait for the end of stream callback. | 90 // Feeding is done, just wait for the end of stream callback. |
91 if (buffer->end_of_stream() || frames_.empty()) { | 91 if (buffer->end_of_stream() || frames_.empty()) { |
92 if (frames_.empty() && !buffer->end_of_stream()) { | 92 if (frames_.empty() && !buffer->end_of_stream()) { |
93 LOG(WARNING) << "Stream emptied without feeding EOS frame"; | 93 LOG(WARNING) << "Stream emptied without feeding EOS frame"; |
94 } | 94 } |
95 | 95 |
96 feeding_completed_ = true; | 96 feeding_completed_ = true; |
(...skipping 25 matching lines...) Expand all Loading... |
122 MediaComponentDevice::kStateUninitialized); | 122 MediaComponentDevice::kStateUninitialized); |
123 ASSERT_TRUE(success); | 123 ASSERT_TRUE(success); |
124 | 124 |
125 if (!eos_cb_.is_null()) { | 125 if (!eos_cb_.is_null()) { |
126 eos_cb_.Run(); | 126 eos_cb_.Run(); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 } // namespace media | 130 } // namespace media |
131 } // namespace chromecast | 131 } // namespace chromecast |
OLD | NEW |