Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: media/video/encoded_video_source.h

Issue 12379011: Interfaces for encoded video sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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 #ifndef MEDIA_VIDEO_ENCODED_VIDEO_SOURCE_H_
6 #define MEDIA_VIDEO_ENCODED_VIDEO_SOURCE_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "media/base/encoded_bitstream_buffer.h"
10 #include "media/video/video_encode_types.h"
11
12 namespace media {
13
14 // Class to represent an encoded video bitstream which originates from an
15 // EncodedVideoSource. The interface is usually obtained through initialization
16 // with OpenBitstream call to EncodedVideoSource. Each EncodedVideoBitstream
17 // instance has only one client, but there can be multiple EncodedVideoBitstream
18 // objects representing the same concrete bitstream from a EncodedVideoSource.
19 //
20 // Client can close the bitstream simply by discarding the scoped_refptr to the
21 // object. Also, if client receives OnDestroyed callback from the bitstream, it
22 // should consider bitstream instance invalid and can discard the pointer to it.
23 class MEDIA_EXPORT EncodedVideoBitstream :
24 public base::RefCountedThreadSafe<EncodedVideoBitstream> {
25 public:
26 // Status codes to inform the client about the reasons for bitstream
27 // destruction.
28 enum DestructionReason {
29 kDestroyedOnRequest = 0, // Bitstream was removed on client's request.
30 kEndOfStream, // End of stream triggered from source.
31 kInvalidConfiguration, // Client tried to initialize the bitstream with
32 // unsupported or invalid configuration.
33 kSourceRemoved, // Unexpected removal of source device, e.g. removal of
34 // webcam from USB connector.
35 kHardwareError, // Hardware has encountered internal error.
36 };
37
38 class MEDIA_EXPORT Client {
39 public:
40 // OnStreaming callback lets the client know that the bitstream has been
41 // successfully created and is streaming. The parameters that the bitstream
42 // has been created with may differ from what client requested when creating
43 // the bitstream and client is expected to examine whether they are
44 // acceptable to it.
45 virtual void OnStreaming(
46 scoped_refptr<EncodedVideoBitstream> bitstream,
47 const VideoEncodingParameters& params) = 0;
48
49 // OnDestroyed tells the client to stop using the bitstream object and
50 // expecting bitstream buffers for the given stream. OnDestroyed will be
51 // called also in case of any unrecoverable failure in the device. After
52 // OnDestroyed is called for a bitstream it is guaranteed that that there
53 // will be no longer pending calls coming in to the client.
54 virtual void OnDestroyed(scoped_refptr<EncodedVideoBitstream> bitstream,
55 DestructionReason reason) = 0;
56
57 // OnBufferReady delivers the captured bitstream buffer by buffer to the
58 // client.
59 virtual void OnBufferReady(
60 scoped_refptr<EncodedVideoBitstream> bitstream,
61 scoped_refptr<const EncodedBitstreamBuffer> buffer) = 0;
62
63 // OnConfigChanged informs about change in bitstream parameters that can
64 // change during runtime.
65 virtual void OnConfigChanged(
66 scoped_refptr<EncodedVideoBitstream> bitstream,
67 const RuntimeVideoEncodingParameters& params) = 0;
68 };
69
70 // Client can request change in runtime configuration by calling TryConfigure
71 // on a bitstream. Until OnConfigChanged callback is called the old
72 // configuration is valid and there may be incoming buffers with the old
73 // configuration. Regardless of whether this call succeeded or not,
74 // OnConfigChanged callback will be issued with the current parameters.
75 virtual void TryConfigure(
76 const RuntimeVideoEncodingParameters& params) = 0;
77
78 // RequestSpecialFrame allows the client to request special frames from the
79 // encoded video bitstream. The effect of the request is only visible in the
80 // bitstream buffers passed to client through the OnBitstreamReady callback.
81 // This request is served on best-effort basis and client is not given any
82 // guarantees of the realization or timing of the request. Flags parameters
83 // will be interpreted in format specific manner using enumerations.
84 virtual void RequestSpecialFrame(int flags) = 0;
85
86 protected:
87 virtual ~EncodedVideoBitstream() {};
88 friend class base::RefCountedThreadSafe<EncodedVideoBitstream>;
89 };
90
91 // Interface to represent any encoded video source. EncodedVideoSource tries
92 // to capture the essentials of what a client of an encoder would expect from
93 // the *output video bitstream*. Therefore EncodedVideoSource does not specify
94 // where the input pictures come from or how the lifetime of the device is
95 // managed. Interface is primarily focused around the concept of bitstream,
96 // discovery the configuration space of such bitstreams from device with video
97 // encoding capability, mechanisms to instantiate such a bitstream, manipulation
98 // of the bitstream properties, reception of interesting bitstream events and
99 // reception of the stream of buffers in the bitstream.
100 //
101 // Anything that provides encoded video bitstream to clients can be an
102 // EncodedVideoSource. Typical examples of this can be video encoder (duh!) and
103 // webcam that has encoding capability. In case of video encoder implementation
104 // would inherit this interface and add at least instantiatiation and
105 // destruction functionality for the encoder instance and some mechanism to feed
106 // the input to it. In case of webcam implementation would again inherit this
107 // same interface and add mechanisms to instantiate and close the webcam, but it
108 // would not have to have a mechanism to feed the input since it has internal
109 // video source.
110 class MEDIA_EXPORT EncodedVideoSource {
111 public:
112 virtual ~EncodedVideoSource() {};
113
114 // GetCapabilities allows the discovery of the limitations encoded video
115 // bitstreams from this source have.
116 virtual VideoEncodingLimits GetLimits() = 0;
117
118 // OpenBitstream returns object for the stream being added. Client must
119 // consider the returned stream valid until OnBitstreamRemoved callback is
120 // called with the id. Client should check the parameters against limits
121 // reported by GetCapabilities before trying to issue a request to add an
122 // encoded bitstream. Returned EncodedVideoBitstream is only a proxy handle
123 // to the actual bitstream object.
124 virtual scoped_refptr<EncodedVideoBitstream> OpenBitstream(
125 EncodedVideoBitstream::Client* client,
126 const VideoEncodingParameters& params) = 0;
127 };
128
129 } // namespace media
130
131 #endif // MEDIA_VIDEO_ENCODED_VIDEO_SOURCE_H_
132
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698