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 #ifndef MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ | 5 #ifndef MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ |
6 #define MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ | 6 #define MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 | 10 |
11 namespace gfx { | 11 namespace gfx { |
12 class Size; | 12 class Size; |
13 } | 13 } |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 class VideoFrame; | 17 class VideoFrame; |
18 | 18 |
19 namespace cast { | 19 namespace cast { |
20 | 20 |
21 // Interface for an object capable of vending video frames. There is no | 21 // Interface for an object capable of vending video frames. There is no |
22 // requirement for a |VideoFrameFactory| to be concurrent but it must not be | 22 // requirement for a |VideoFrameFactory| to be concurrent but it must not be |
23 // pinned to a specific thread. Indeed, |VideoFrameFactory| implementations are | 23 // pinned to a specific thread. Indeed, |VideoFrameFactory| implementations are |
24 // created by cast on the main cast thread then used by unknown client threads | 24 // created by cast on the main cast thread then used by unknown client threads |
25 // via the |VideoFrameInput| interface. | 25 // via the |VideoFrameInput| interface. |
26 // | 26 // |
27 // Clients are responsible for serialzing access to a |VideoFrameFactory|. | 27 // Clients are responsible for serialzing access to a |VideoFrameFactory|. |
28 // Generally speaking, it is expected that a client will be using these objects | 28 // Generally speaking, it is expected that a client will be using these objects |
29 // from a rendering thread or callback (which may execute on different threads | 29 // from a rendering thread or callback (which may execute on different threads |
30 // but never concurrently with itself). Forcing every implementation to take a | 30 // but never concurrently with itself). |
31 // lock, even with no contention, is an unnecessary cost, especially on mobile | |
32 // platforms. | |
33 class VideoFrameFactory { | 31 class VideoFrameFactory { |
34 public: | 32 public: |
35 virtual ~VideoFrameFactory() {} | 33 virtual ~VideoFrameFactory() {} |
36 | 34 |
37 // Creates a |VideoFrame| suitable for input via |InsertRawVideoFrame|. Frames | 35 // Creates a |VideoFrame| suitable for input via |InsertRawVideoFrame|. Frames |
38 // obtained in this manner may provide benefits such memory reuse and affinity | 36 // obtained in this manner may provide benefits such memory reuse and affinity |
39 // with the encoder. The format is guaranteed to be I420 or NV12. | 37 // with the encoder. The format is guaranteed to be I420 or NV12. |
40 // | 38 // |
41 // This can transiently return null if the encoder is not yet initialized or | 39 // This can transiently return null if the encoder is not yet initialized or |
42 // is re-initializing. | 40 // is re-initializing. Note however that if an encoder does support optimized |
| 41 // frames, its |VideoFrameFactory| must eventually return frames. In practice, |
| 42 // this means that |MaybeCreateFrame| must somehow signal the encoder to |
| 43 // perform whatever initialization is needed to eventually produce frames. |
43 virtual scoped_refptr<VideoFrame> MaybeCreateFrame( | 44 virtual scoped_refptr<VideoFrame> MaybeCreateFrame( |
44 const gfx::Size& frame_size, base::TimeDelta timestamp) = 0; | 45 const gfx::Size& frame_size, base::TimeDelta timestamp) = 0; |
45 }; | 46 }; |
46 | 47 |
47 } // namespace cast | 48 } // namespace cast |
48 } // namespace media | 49 } // namespace media |
49 | 50 |
50 #endif // MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ | 51 #endif // MEDIA_CAST_SENDER_VIDEO_FRAME_FACTORY_H_ |
OLD | NEW |