Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / media / cast / sender / fake_software_video_encoder.cc
blob7a2a333153e11eaa34b67ad93e44c335040627d9
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
3 // found in the LICENSE file.
5 #include "media/cast/sender/fake_software_video_encoder.h"
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9 #include "media/base/video_frame.h"
10 #include "media/cast/net/cast_transport_config.h"
12 #ifndef OFFICIAL_BUILD
14 namespace media {
15 namespace cast {
17 FakeSoftwareVideoEncoder::FakeSoftwareVideoEncoder(
18 const VideoSenderConfig& video_config)
19 : video_config_(video_config),
20 next_frame_is_key_(true),
21 frame_id_(0),
22 frame_id_to_reference_(0),
23 frame_size_(0) {
26 FakeSoftwareVideoEncoder::~FakeSoftwareVideoEncoder() {}
28 void FakeSoftwareVideoEncoder::Initialize() {}
30 void FakeSoftwareVideoEncoder::Encode(
31 const scoped_refptr<media::VideoFrame>& video_frame,
32 const base::TimeTicks& reference_time,
33 EncodedFrame* encoded_frame) {
34 DCHECK(encoded_frame);
36 if (video_frame->visible_rect().size() != last_frame_size_) {
37 next_frame_is_key_ = true;
38 last_frame_size_ = video_frame->visible_rect().size();
41 encoded_frame->frame_id = frame_id_++;
42 if (next_frame_is_key_) {
43 encoded_frame->dependency = EncodedFrame::KEY;
44 encoded_frame->referenced_frame_id = encoded_frame->frame_id;
45 next_frame_is_key_ = false;
46 } else {
47 encoded_frame->dependency = EncodedFrame::DEPENDENT;
48 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1;
50 encoded_frame->rtp_timestamp =
51 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency);
52 encoded_frame->reference_time = reference_time;
54 base::DictionaryValue values;
55 values.SetBoolean("key",
56 encoded_frame->dependency == EncodedFrame::KEY);
57 values.SetInteger("ref", encoded_frame->referenced_frame_id);
58 values.SetInteger("id", encoded_frame->frame_id);
59 values.SetInteger("size", frame_size_);
60 base::JSONWriter::Write(&values, &encoded_frame->data);
61 encoded_frame->data.resize(
62 std::max<size_t>(encoded_frame->data.size(), frame_size_), ' ');
65 void FakeSoftwareVideoEncoder::UpdateRates(uint32 new_bitrate) {
66 frame_size_ = new_bitrate / video_config_.max_frame_rate / 8;
69 void FakeSoftwareVideoEncoder::GenerateKeyFrame() {
70 next_frame_is_key_ = true;
73 void FakeSoftwareVideoEncoder::LatestFrameIdToReference(uint32 frame_id) {
74 frame_id_to_reference_ = frame_id;
77 } // namespace cast
78 } // namespace media
80 #endif