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