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 "media/cast/sender/fake_software_video_encoder.h" | 5 #include "media/cast/sender/fake_software_video_encoder.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "media/base/video_frame.h" | 9 #include "media/base/video_frame.h" |
| 10 #include "media/cast/net/cast_transport_config.h" |
10 | 11 |
11 #ifndef OFFICIAL_BUILD | 12 #ifndef OFFICIAL_BUILD |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 namespace cast { | 15 namespace cast { |
15 | 16 |
16 FakeSoftwareVideoEncoder::FakeSoftwareVideoEncoder( | 17 FakeSoftwareVideoEncoder::FakeSoftwareVideoEncoder( |
17 const VideoSenderConfig& video_config) | 18 const VideoSenderConfig& video_config) |
18 : video_config_(video_config), | 19 : video_config_(video_config), |
19 next_frame_is_key_(true), | 20 next_frame_is_key_(true), |
20 frame_id_(0), | 21 frame_id_(0), |
21 frame_id_to_reference_(0), | 22 frame_id_to_reference_(0), |
22 frame_size_(0) { | 23 frame_size_(0) { |
23 } | 24 } |
24 | 25 |
25 FakeSoftwareVideoEncoder::~FakeSoftwareVideoEncoder() {} | 26 FakeSoftwareVideoEncoder::~FakeSoftwareVideoEncoder() {} |
26 | 27 |
27 void FakeSoftwareVideoEncoder::Initialize() {} | 28 void FakeSoftwareVideoEncoder::Initialize() {} |
28 | 29 |
29 void FakeSoftwareVideoEncoder::Encode( | 30 void FakeSoftwareVideoEncoder::Encode( |
30 const scoped_refptr<media::VideoFrame>& video_frame, | 31 const scoped_refptr<media::VideoFrame>& video_frame, |
31 const base::TimeTicks& reference_time, | 32 const base::TimeTicks& reference_time, |
32 SenderEncodedFrame* encoded_frame) { | 33 EncodedFrame* encoded_frame) { |
33 DCHECK(encoded_frame); | 34 DCHECK(encoded_frame); |
34 | 35 |
35 if (video_frame->visible_rect().size() != last_frame_size_) { | 36 if (video_frame->visible_rect().size() != last_frame_size_) { |
36 next_frame_is_key_ = true; | 37 next_frame_is_key_ = true; |
37 last_frame_size_ = video_frame->visible_rect().size(); | 38 last_frame_size_ = video_frame->visible_rect().size(); |
38 } | 39 } |
39 | 40 |
40 encoded_frame->frame_id = frame_id_++; | 41 encoded_frame->frame_id = frame_id_++; |
41 if (next_frame_is_key_) { | 42 if (next_frame_is_key_) { |
42 encoded_frame->dependency = EncodedFrame::KEY; | 43 encoded_frame->dependency = EncodedFrame::KEY; |
43 encoded_frame->referenced_frame_id = encoded_frame->frame_id; | 44 encoded_frame->referenced_frame_id = encoded_frame->frame_id; |
44 next_frame_is_key_ = false; | 45 next_frame_is_key_ = false; |
45 } else { | 46 } else { |
46 encoded_frame->dependency = EncodedFrame::DEPENDENT; | 47 encoded_frame->dependency = EncodedFrame::DEPENDENT; |
47 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1; | 48 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1; |
48 } | 49 } |
49 encoded_frame->rtp_timestamp = | 50 encoded_frame->rtp_timestamp = |
50 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); | 51 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); |
51 encoded_frame->reference_time = reference_time; | 52 encoded_frame->reference_time = reference_time; |
52 | 53 |
53 base::DictionaryValue values; | 54 base::DictionaryValue values; |
54 values.SetBoolean("key", | 55 values.SetBoolean("key", |
55 encoded_frame->dependency == EncodedFrame::KEY); | 56 encoded_frame->dependency == EncodedFrame::KEY); |
56 values.SetInteger("ref", encoded_frame->referenced_frame_id); | 57 values.SetInteger("ref", encoded_frame->referenced_frame_id); |
57 values.SetInteger("id", encoded_frame->frame_id); | 58 values.SetInteger("id", encoded_frame->frame_id); |
58 values.SetInteger("size", frame_size_); | 59 values.SetInteger("size", frame_size_); |
59 base::JSONWriter::Write(values, &encoded_frame->data); | 60 base::JSONWriter::Write(values, &encoded_frame->data); |
60 encoded_frame->data.resize( | 61 encoded_frame->data.resize( |
61 std::max<size_t>(encoded_frame->data.size(), frame_size_), ' '); | 62 std::max<size_t>(encoded_frame->data.size(), frame_size_), ' '); |
62 | |
63 if (encoded_frame->dependency == EncodedFrame::KEY) { | |
64 encoded_frame->deadline_utilization = 1.0; | |
65 encoded_frame->lossy_utilization = 6.0; | |
66 } else { | |
67 encoded_frame->deadline_utilization = 0.8; | |
68 encoded_frame->lossy_utilization = 0.8; | |
69 } | |
70 } | 63 } |
71 | 64 |
72 void FakeSoftwareVideoEncoder::UpdateRates(uint32 new_bitrate) { | 65 void FakeSoftwareVideoEncoder::UpdateRates(uint32 new_bitrate) { |
73 frame_size_ = new_bitrate / video_config_.max_frame_rate / 8; | 66 frame_size_ = new_bitrate / video_config_.max_frame_rate / 8; |
74 } | 67 } |
75 | 68 |
76 void FakeSoftwareVideoEncoder::GenerateKeyFrame() { | 69 void FakeSoftwareVideoEncoder::GenerateKeyFrame() { |
77 next_frame_is_key_ = true; | 70 next_frame_is_key_ = true; |
78 } | 71 } |
79 | 72 |
80 void FakeSoftwareVideoEncoder::LatestFrameIdToReference(uint32 frame_id) { | 73 void FakeSoftwareVideoEncoder::LatestFrameIdToReference(uint32 frame_id) { |
81 frame_id_to_reference_ = frame_id; | 74 frame_id_to_reference_ = frame_id; |
82 } | 75 } |
83 | 76 |
84 } // namespace cast | 77 } // namespace cast |
85 } // namespace media | 78 } // namespace media |
86 | 79 |
87 #endif | 80 #endif |
OLD | NEW |