summaryrefslogtreecommitdiffstats
path: root/media/cast/sender/video_encoder.h
blob: 92e8547769981ba7294dd4129552e107b91f167c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_SENDER_VIDEO_ENCODER_H_
#define MEDIA_CAST_SENDER_VIDEO_ENCODER_H_

#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "media/base/video_frame.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"

namespace media {
namespace cast {

class VideoFrameFactory;

// All these functions are called from the main cast thread.
class VideoEncoder {
 public:
  typedef base::Callback<void(scoped_ptr<EncodedFrame>)> FrameEncodedCallback;

  virtual ~VideoEncoder() {}

  // Returns true if the size of video frames passed in successive calls to
  // EncodedVideoFrame() can vary.
  virtual bool CanEncodeVariedFrameSizes() const = 0;

  // If true is returned, the Encoder has accepted the request and will process
  // it asynchronously, running |frame_encoded_callback| on the MAIN
  // CastEnvironment thread with the result.  If false is returned, nothing
  // happens and the callback will not be run.
  virtual bool EncodeVideoFrame(
      const scoped_refptr<media::VideoFrame>& video_frame,
      const base::TimeTicks& reference_time,
      const FrameEncodedCallback& frame_encoded_callback) = 0;

  // Inform the encoder about the new target bit rate.
  virtual void SetBitRate(int new_bit_rate) = 0;

  // Inform the encoder to encode the next frame as a key frame.
  virtual void GenerateKeyFrame() = 0;

  // Inform the encoder to only reference frames older or equal to frame_id;
  virtual void LatestFrameIdToReference(uint32 frame_id) = 0;

  // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with
  // encoder affinity (defined as offering some sort of performance benefit).
  // This is an optional capability and by default returns null.
  virtual scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory();

  // Instructs the encoder to finish and emit all frames that have been
  // submitted for encoding. An encoder may hold a certain number of frames for
  // analysis. Under certain network conditions, particularly when there is
  // network congestion, it is necessary to flush out of the encoder all
  // submitted frames so that eventually new frames may be encoded. Like
  // EncodeVideoFrame(), the encoder will process this request asynchronously.
  virtual void EmitFrames();
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_SENDER_VIDEO_ENCODER_H_