Home | History | Annotate | Download | only in sender
      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.
      4 
      5 #include "media/cast/sender/fake_software_video_encoder.h"
      6 
      7 #include "base/json/json_writer.h"
      8 #include "base/values.h"
      9 #include "media/cast/net/cast_transport_config.h"
     10 
     11 #ifndef OFFICIAL_BUILD
     12 
     13 namespace media {
     14 namespace cast {
     15 
     16 FakeSoftwareVideoEncoder::FakeSoftwareVideoEncoder(
     17     const VideoSenderConfig& video_config)
     18     : video_config_(video_config),
     19       next_frame_is_key_(true),
     20       frame_id_(0),
     21       frame_id_to_reference_(0),
     22       frame_size_(0) {
     23 }
     24 
     25 FakeSoftwareVideoEncoder::~FakeSoftwareVideoEncoder() {}
     26 
     27 void FakeSoftwareVideoEncoder::Initialize() {}
     28 
     29 bool FakeSoftwareVideoEncoder::Encode(
     30     const scoped_refptr<media::VideoFrame>& video_frame,
     31     EncodedFrame* encoded_image) {
     32   encoded_image->frame_id = frame_id_++;
     33   if (next_frame_is_key_) {
     34     encoded_image->dependency = EncodedFrame::KEY;
     35     encoded_image->referenced_frame_id = encoded_image->frame_id;
     36     next_frame_is_key_ = false;
     37   } else {
     38     encoded_image->dependency = EncodedFrame::DEPENDENT;
     39     encoded_image->referenced_frame_id = encoded_image->frame_id - 1;
     40   }
     41 
     42   base::DictionaryValue values;
     43   values.SetBoolean("key",
     44                     encoded_image->dependency == EncodedFrame::KEY);
     45   values.SetInteger("ref", encoded_image->referenced_frame_id);
     46   values.SetInteger("id", encoded_image->frame_id);
     47   values.SetInteger("size", frame_size_);
     48   base::JSONWriter::Write(&values, &encoded_image->data);
     49   encoded_image->data.resize(
     50       std::max<size_t>(encoded_image->data.size(), frame_size_), ' ');
     51   return true;
     52 }
     53 
     54 void FakeSoftwareVideoEncoder::UpdateRates(uint32 new_bitrate) {
     55   frame_size_ = new_bitrate / video_config_.max_frame_rate / 8;
     56 }
     57 
     58 void FakeSoftwareVideoEncoder::GenerateKeyFrame() {
     59   next_frame_is_key_ = true;
     60 }
     61 
     62 void FakeSoftwareVideoEncoder::LatestFrameIdToReference(uint32 frame_id) {
     63   frame_id_to_reference_ = frame_id;
     64 }
     65 
     66 }  // namespace cast
     67 }  // namespace media
     68 
     69 #endif
     70