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

Side by Side Diff: chromecast/public/media/media_component_device.h

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another round of review feedback Created 5 years, 4 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
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 CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ 5 #ifndef CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_
6 #define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ 6 #define CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_
7 7
8 #include <stdint.h>
8 #include <string> 9 #include <string>
9 10
10 #include "base/basictypes.h" 11 #include "cast_key_system.h"
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/time/time.h"
16 12
17 namespace chromecast { 13 namespace chromecast {
18 namespace media { 14 namespace media {
19 class DecoderBufferBase; 15 class CastDecoderBuffer;
20 class DecryptContext;
21 16
22 // MediaComponentDevice - 17 // MediaComponentDevice -
23 // 18 //
24 // State machine: 19 // State machine:
25 // -------------- kRunning <--- 20 // -------------- kRunning <---
26 // | ^ | 21 // | ^ |
27 // v | | 22 // v | |
28 // kUninitialized <--> kIdle -------------- | 23 // kUninitialized <--> kIdle -------------- |
29 // ^ | | 24 // ^ | |
30 // | v | 25 // | v |
31 // -------------- kPaused <---- 26 // -------------- kPaused <----
32 // {any state} --> kError 27 // {any state} --> kError
33 // kError --> kUninitialized 28 // kError --> kUninitialized
34 // 29 //
35 // Notes: 30 // Notes:
36 // - Hardware resources are acquired when transitioning from the 31 // - Hardware resources are acquired when transitioning from the
37 // |kUninitialized| state to the |kIdle| state. 32 // |kUninitialized| state to the |kIdle| state.
38 // - Buffers can be pushed only in the kRunning or kPaused states. 33 // - Buffers can be pushed only in the kRunning or kPaused states.
39 // - The end of stream is signaled through a special buffer. 34 // - The end of stream is signaled through a special buffer.
40 // Once the end of stream buffer is fed, no other buffer 35 // Once the end of stream buffer is fed, no other buffer
41 // can be fed until the FSM goes through the kIdle state again. 36 // can be fed until the FSM goes through the kIdle state again.
42 // - In both kPaused and kRunning states, frames can be fed. 37 // - In both kPaused and kRunning states, frames can be fed.
43 // However, frames are possibly rendered only in the kRunning state. 38 // However, frames are possibly rendered only in the kRunning state.
44 // - In the kRunning state, frames are rendered according to the clock rate. 39 // - In the kRunning state, frames are rendered according to the clock rate.
45 // - All the hardware resources must be released in the |kError| state. 40 // - All the hardware resources must be released in the |kError| state.
46 // 41 //
47 class MediaComponentDevice 42 class MediaComponentDevice {
48 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
49 public: 43 public:
50 enum State { 44 enum State {
51 kStateUninitialized, 45 kStateUninitialized,
52 kStateIdle, 46 kStateIdle,
53 kStateRunning, 47 kStateRunning,
54 kStatePaused, 48 kStatePaused,
55 kStateError, 49 kStateError,
56 }; 50 };
57 51
58 enum FrameStatus { 52 enum FrameStatus {
59 kFrameSuccess, 53 kFrameSuccess,
60 kFrameFailed, 54 kFrameFailed,
61 kFramePending, 55 kFramePending,
62 }; 56 };
63 typedef base::Callback<void(FrameStatus)> FrameStatusCB;
64 57
65 struct Client { 58 // Interface for receiving status when PushFrame has completed.
66 Client(); 59 class FrameStatusCB {
67 ~Client(); 60 public:
61 virtual ~FrameStatusCB() {}
62 virtual void Run(FrameStatus status) = 0;
63 };
68 64
69 // Invoked when playback reaches the end of stream. 65 // Client callbacks interface
70 base::Closure eos_cb; 66 class Client {
67 public:
68 virtual ~Client() {}
69 virtual void OnEndOfStream() = 0;
71 }; 70 };
72 71
73 // The statistics are computed since the media component left the idle state. 72 // The statistics are computed since the media component left the idle state.
74 // For video, a sample is defined as a frame. 73 // For video, a sample is defined as a frame.
75 struct Statistics { 74 struct Statistics {
76 uint64 decoded_bytes; 75 uint64_t decoded_bytes;
77 uint64 decoded_samples; 76 uint64_t decoded_samples;
78 uint64 dropped_samples; 77 uint64_t dropped_samples;
79 }; 78 };
80 79
81 // Returns whether or not transitioning from |state1| to |state2| is valid. 80 // Info on pipeline latency: amount of data in pipeline not rendered yet,
82 static bool IsValidStateTransition(State state1, State state2); 81 // and timestamp of system clock (must be CLOCK_MONOTONIC) at which delay
82 // measurement was taken. Both times in microseconds.
83 struct RenderingDelay {
84 RenderingDelay() : delay(INT64_MIN), timestamp(INT64_MIN) {}
85 RenderingDelay(int64_t delay_in, int64_t timestamp_in)
86 : delay(delay_in), timestamp(timestamp_in) {}
87 int64_t delay;
88 int64_t timestamp;
89 };
83 90
84 // Returns string representation of state (for logging) 91 virtual ~MediaComponentDevice() {}
85 static std::string StateToString(const State& state);
86 92
87 MediaComponentDevice(); 93 // Register |client| as the media event handler. Implementation
88 virtual ~MediaComponentDevice(); 94 // takes ownership of |client|.
89 95 virtual void SetClient(Client* client) = 0;
90 // Register |client| as the media event handler.
91 virtual void SetClient(const Client& client) = 0;
92 96
93 // Changes the state and performs any necessary transitions. 97 // Changes the state and performs any necessary transitions.
94 // Returns true when successful. 98 // Returns true when successful.
95 virtual bool SetState(State new_state) = 0; 99 virtual bool SetState(State new_state) = 0;
96 100
97 // Returns the current state of the media component. 101 // Returns the current state of the media component.
98 virtual State GetState() const = 0; 102 virtual State GetState() const = 0;
99 103
100 // Sets the time where rendering should start. 104 // Sets the time where rendering should start.
101 // Return true when successful. 105 // Return true when successful.
102 // Can only be invoked in state kStateIdle. 106 // Can only be invoked in state kStateIdle.
103 virtual bool SetStartPts(base::TimeDelta time) = 0; 107 virtual bool SetStartPts(int64_t microseconds) = 0;
104 108
105 // Pushes a frame. 109 // Pushes a frame.
110 // The implementation takes ownership of |buffer|.
106 // |completion_cb| is only invoked if the returned value is |kFramePending|. 111 // |completion_cb| is only invoked if the returned value is |kFramePending|.
107 // In this specific case, no additional frame can be pushed before 112 // In this specific case, no additional frame can be pushed before
108 // |completion_cb| is invoked. 113 // |completion_cb| is invoked.
109 // Note: |completion_cb| cannot be invoked with |kFramePending|. 114 // Note: |completion_cb| cannot be invoked with |kFramePending|.
110 // Note: pushing the pending frame should be aborted when the state goes back 115 // Note: pushing the pending frame should be aborted when the state goes back
111 // to kStateIdle. |completion_cb| is not invoked in that case. 116 // to kStateIdle. |completion_cb| is not invoked in that case.
112 virtual FrameStatus PushFrame( 117 // Implementation must take ownership of completion_cb and free after calling.
113 const scoped_refptr<DecryptContext>& decrypt_context, 118 virtual FrameStatus PushFrame(CastKeySystem key_system,
114 const scoped_refptr<DecoderBufferBase>& buffer, 119 CastDecoderBuffer* buffer,
115 const FrameStatusCB& completion_cb) = 0; 120 FrameStatusCB* completion_cb) = 0;
116
117 // Returns the rendering time of the latest rendered sample.
118 // Can be invoked only in states kStateRunning or kStatePaused.
119 // Returns |kNoTimestamp()| if the playback time cannot be retrieved.
120 virtual base::TimeDelta GetRenderingTime() const = 0;
121 121
122 // Returns the pipeline latency: i.e. the amount of data 122 // Returns the pipeline latency: i.e. the amount of data
123 // in the pipeline that have not been rendered yet. 123 // in the pipeline that have not been rendered yet, in microseconds.
124 // Returns |kNoTimestamp()| if the latency is not available. 124 // Returns delay = INT64_MIN if the latency is not available.
125 virtual base::TimeDelta GetRenderingDelay() const = 0; 125 virtual RenderingDelay GetRenderingDelay() const = 0;
126 126
127 // Returns the playback statistics. Statistics are computed since the media 127 // Returns the playback statistics. Statistics are computed since the media
128 // component left the idle state. 128 // component left the idle state.
129 // Returns true when successful. 129 // Returns true when successful.
130 // Can only be invoked in state kStateRunning. 130 // Can only be invoked in state kStateRunning.
131 virtual bool GetStatistics(Statistics* stats) const = 0; 131 virtual bool GetStatistics(Statistics* stats) const = 0;
132
133 private:
134 DISALLOW_COPY_AND_ASSIGN(MediaComponentDevice);
135 }; 132 };
136 133
137 } // namespace media 134 } // namespace media
138 } // namespace chromecast 135 } // namespace chromecast
139 136
140 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ 137 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698