Chromium Code Reviews| Index: chromecast/public/media/media_component_device.h |
| diff --git a/chromecast/media/cma/backend/media_component_device.h b/chromecast/public/media/media_component_device.h |
| similarity index 56% |
| rename from chromecast/media/cma/backend/media_component_device.h |
| rename to chromecast/public/media/media_component_device.h |
| index fd62d8dfa2ff6b1b4a779ceae1c6014a7b3a163a..6398b21a2a1ecb9bd8d18bb4e25e42f225e3c1e3 100644 |
| --- a/chromecast/media/cma/backend/media_component_device.h |
| +++ b/chromecast/public/media/media_component_device.h |
| @@ -2,22 +2,18 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ |
| -#define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ |
| +#ifndef CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_ |
| +#define CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_ |
| +#include <stdint.h> |
| #include <string> |
| -#include "base/basictypes.h" |
| -#include "base/callback.h" |
| -#include "base/macros.h" |
| -#include "base/memory/ref_counted.h" |
| -#include "base/threading/non_thread_safe.h" |
| -#include "base/time/time.h" |
| +#include "cast_key_system.h" |
| +#include "chromecast/public/time_delta.h" |
| namespace chromecast { |
| namespace media { |
| -class DecoderBufferBase; |
| -class DecryptContext; |
| +class DecoderBuffer; |
| // MediaComponentDevice - |
| // |
| @@ -44,8 +40,7 @@ class DecryptContext; |
| // - In the kRunning state, frames are rendered according to the clock rate. |
| // - All the hardware resources must be released in the |kError| state. |
| // |
| -class MediaComponentDevice |
| - : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| +class MediaComponentDevice { |
| public: |
| enum State { |
| kStateUninitialized, |
| @@ -60,35 +55,77 @@ class MediaComponentDevice |
| kFrameFailed, |
| kFramePending, |
| }; |
| - typedef base::Callback<void(FrameStatus)> FrameStatusCB; |
| - struct Client { |
| - Client(); |
| - ~Client(); |
| + // Interface for receiving status when PushFrame has completed. |
| + class FrameStatusCB { |
| + public: |
| + virtual ~FrameStatusCB() {} |
| + virtual void Run(FrameStatus status) = 0; |
| + }; |
| - // Invoked when playback reaches the end of stream. |
| - base::Closure eos_cb; |
| + // Client callbacks interface |
| + class Client { |
| + public: |
| + virtual ~Client() {} |
| + virtual void OnEndOfStream() = 0; |
| }; |
| // The statistics are computed since the media component left the idle state. |
| // For video, a sample is defined as a frame. |
| struct Statistics { |
| - uint64 decoded_bytes; |
| - uint64 decoded_samples; |
| - uint64 dropped_samples; |
| + uint64_t decoded_bytes; |
| + uint64_t decoded_samples; |
| + uint64_t dropped_samples; |
| }; |
| // Returns whether or not transitioning from |state1| to |state2| is valid. |
| - static bool IsValidStateTransition(State state1, State state2); |
| + inline static bool IsValidStateTransition(State state1, State state2) { |
| + if (state2 == state1) |
| + return true; |
| + |
| + // All states can transition to |kStateError|. |
| + bool is_transition_valid = (state2 == kStateError); |
| + |
| + // All the other valid FSM transitions. |
| + is_transition_valid = |
| + is_transition_valid || |
| + (state1 == kStateUninitialized && (state2 == kStateIdle)) || |
| + (state1 == kStateIdle && |
| + (state2 == kStateRunning || state2 == kStatePaused || |
| + state2 == kStateUninitialized)) || |
| + (state1 == kStatePaused && |
| + (state2 == kStateIdle || state2 == kStateRunning)) || |
| + (state1 == kStateRunning && |
| + (state2 == kStateIdle || state2 == kStatePaused)) || |
| + (state1 == kStateError && (state2 == kStateUninitialized)); |
| + |
| + return is_transition_valid; |
| + } |
| // Returns string representation of state (for logging) |
| - static std::string StateToString(const State& state); |
| - |
| - MediaComponentDevice(); |
| - virtual ~MediaComponentDevice(); |
| - |
| - // Register |client| as the media event handler. |
| - virtual void SetClient(const Client& client) = 0; |
| + inline static std::string StateToString(const State& state) { |
| + switch (state) { |
| + case kStateUninitialized: |
| + return "Uninitialized"; |
| + case kStateIdle: |
| + return "Idle"; |
| + case kStateRunning: |
| + return "Running"; |
| + case kStatePaused: |
| + return "Paused"; |
| + case kStateError: |
| + return "Error"; |
| + default: |
| + return ""; |
| + } |
| + } |
|
byungchul
2015/07/27 18:22:23
Are they necessary for shlibs?
halliwell
2015/07/28 02:19:36
yes, all vendors rely on these currently.
byungchul
2015/07/28 18:05:43
See the other comment in media_clock_device.h
halliwell
2015/07/28 23:26:06
As for clock, removed from public headers.
|
| + |
| + MediaComponentDevice() {} |
| + virtual ~MediaComponentDevice() {} |
| + |
| + // Register |client| as the media event handler. Implementation |
| + // takes ownership of |client|. |
| + virtual void SetClient(Client* client) = 0; |
| // Changes the state and performs any necessary transitions. |
| // Returns true when successful. |
| @@ -100,38 +137,31 @@ class MediaComponentDevice |
| // Sets the time where rendering should start. |
| // Return true when successful. |
| // Can only be invoked in state kStateIdle. |
| - virtual bool SetStartPts(base::TimeDelta time) = 0; |
| + virtual bool SetStartPts(TimeDelta time) = 0; |
| // Pushes a frame. |
| + // The implementation takes ownership of |buffer|. |
| // |completion_cb| is only invoked if the returned value is |kFramePending|. |
| // In this specific case, no additional frame can be pushed before |
| // |completion_cb| is invoked. |
| // Note: |completion_cb| cannot be invoked with |kFramePending|. |
| // Note: pushing the pending frame should be aborted when the state goes back |
| // to kStateIdle. |completion_cb| is not invoked in that case. |
| - virtual FrameStatus PushFrame( |
| - const scoped_refptr<DecryptContext>& decrypt_context, |
| - const scoped_refptr<DecoderBufferBase>& buffer, |
| - const FrameStatusCB& completion_cb) = 0; |
| - |
| - // Returns the rendering time of the latest rendered sample. |
| - // Can be invoked only in states kStateRunning or kStatePaused. |
| - // Returns |kNoTimestamp()| if the playback time cannot be retrieved. |
| - virtual base::TimeDelta GetRenderingTime() const = 0; |
| + // Implementation must take ownership of completion_cb and free after calling. |
| + virtual FrameStatus PushFrame(CastKeySystem key_system, |
| + DecoderBuffer* buffer, |
| + FrameStatusCB* completion_cb) = 0; |
| // Returns the pipeline latency: i.e. the amount of data |
| // in the pipeline that have not been rendered yet. |
| // Returns |kNoTimestamp()| if the latency is not available. |
| - virtual base::TimeDelta GetRenderingDelay() const = 0; |
| + virtual TimeDelta GetRenderingDelay() const = 0; |
| // Returns the playback statistics. Statistics are computed since the media |
| // component left the idle state. |
| // Returns true when successful. |
| // Can only be invoked in state kStateRunning. |
| virtual bool GetStatistics(Statistics* stats) const = 0; |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(MediaComponentDevice); |
| }; |
| } // namespace media |