Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1173)

Side by Side Diff: media/remoting/fake_demuxer_stream_provider.cc

Issue 2668393002: Rename DemuxerStreamProvider into MediaResource (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "media/remoting/fake_demuxer_stream_provider.h"
6
7 #include <vector>
8
9 #include "base/callback_helpers.h"
10 #include "media/base/decoder_buffer.h"
11 #include "media/base/media_util.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using testing::_;
15 using testing::Invoke;
16 using testing::Return;
17
18 namespace media {
19 namespace remoting {
20
21 FakeDemuxerStream::FakeDemuxerStream(bool is_audio) {
22 type_ = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO;
23 if (is_audio) {
24 audio_config_.Initialize(kCodecAAC, kSampleFormatS16, CHANNEL_LAYOUT_STEREO,
25 38400, std::vector<uint8_t>(), Unencrypted(),
26 base::TimeDelta(), 0);
27 } else {
28 gfx::Size size(640, 480);
29 gfx::Rect rect(0, 0, 640, 480);
30 video_config_.Initialize(kCodecH264, H264PROFILE_BASELINE,
31 PIXEL_FORMAT_I420, COLOR_SPACE_SD_REC601, size,
32 rect, size, std::vector<uint8_t>(), Unencrypted());
33 }
34 ON_CALL(*this, Read(_))
35 .WillByDefault(Invoke(this, &FakeDemuxerStream::FakeRead));
36 }
37
38 FakeDemuxerStream::~FakeDemuxerStream() = default;
39
40 void FakeDemuxerStream::FakeRead(const ReadCB& read_cb) {
41 if (buffer_queue_.empty()) {
42 // Silent return to simulate waiting for buffer available.
43 pending_read_cb_ = read_cb;
44 return;
45 }
46 scoped_refptr<DecoderBuffer> buffer = buffer_queue_.front();
47 buffer_queue_.pop_front();
48 read_cb.Run(kOk, buffer);
49 }
50
51 AudioDecoderConfig FakeDemuxerStream::audio_decoder_config() {
52 return audio_config_;
53 }
54
55 VideoDecoderConfig FakeDemuxerStream::video_decoder_config() {
56 return video_config_;
57 }
58
59 DemuxerStream::Type FakeDemuxerStream::type() const {
60 return type_;
61 }
62
63 DemuxerStream::Liveness FakeDemuxerStream::liveness() const {
64 return LIVENESS_UNKNOWN;
65 }
66
67 bool FakeDemuxerStream::SupportsConfigChanges() {
68 return false;
69 }
70
71 VideoRotation FakeDemuxerStream::video_rotation() {
72 return VIDEO_ROTATION_0;
73 }
74
75 bool FakeDemuxerStream::enabled() const {
76 return false;
77 }
78
79 void FakeDemuxerStream::CreateFakeFrame(size_t size,
80 bool key_frame,
81 int pts_ms) {
82 std::vector<uint8_t> buffer(size);
83 // Assign each byte in the buffer its index mod 256.
84 for (size_t i = 0; i < size; ++i) {
85 buffer[i] = static_cast<uint8_t>(i & 0xFF);
86 }
87 base::TimeDelta pts = base::TimeDelta::FromMilliseconds(pts_ms);
88
89 // To DecoderBuffer
90 scoped_refptr<DecoderBuffer> input_buffer =
91 DecoderBuffer::CopyFrom(buffer.data(), size);
92 input_buffer->set_timestamp(pts);
93 input_buffer->set_is_key_frame(key_frame);
94
95 // Sends frame out if there is pending read callback. Otherwise, stores it
96 // in the buffer queue.
97 if (pending_read_cb_.is_null()) {
98 buffer_queue_.push_back(input_buffer);
99 } else {
100 base::ResetAndReturn(&pending_read_cb_).Run(kOk, input_buffer);
101 }
102 }
103
104 FakeDemuxerStreamProvider::FakeDemuxerStreamProvider()
105 : demuxer_stream_(new FakeDemuxerStream(true)) {}
106
107 FakeDemuxerStreamProvider::~FakeDemuxerStreamProvider() {}
108
109 DemuxerStream* FakeDemuxerStreamProvider::GetStream(DemuxerStream::Type type) {
110 if (type == DemuxerStream::AUDIO)
111 return reinterpret_cast<DemuxerStream*>(demuxer_stream_.get());
112 return nullptr;
113 }
114
115 } // namespace remoting
116 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698