Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "media/base/android/media_codec_player_state.h" | |
| 2 #include "media/base/android/media_codec_player.h" | |
| 3 #include "media/base/buffers.h" | |
| 4 | |
| 5 namespace media { | |
| 6 | |
| 7 // Every method is called on the Media thread | |
| 8 | |
|
qinmin
2015/05/13 23:17:32
nit:extra line
Tima Vaisburd
2015/05/14 00:14:59
Removed.
| |
| 9 | |
| 10 // MediaCodecPlayerState (superclass) | |
| 11 | |
| 12 // By default, set configs for the future use | |
| 13 void MediaCodecPlayerState::EventDemuxerConfigsAvailable( | |
| 14 MediaCodecPlayer* player, const DemuxerConfigs& configs) { | |
| 15 player->SetDemuxerConfigs(configs); | |
| 16 } | |
| 17 | |
| 18 // By default, set the Error state that blocks all events | |
| 19 void MediaCodecPlayerState::EventError(MediaCodecPlayer* player) { | |
| 20 player->SetState(StateError::Instance()); | |
| 21 } | |
| 22 | |
| 23 // Stop decoders synchronously. | |
| 24 // TODO: as it seems to work for every state, consider moving Release() | |
| 25 // out of the state machine. | |
| 26 void MediaCodecPlayerState::EventRelease(MediaCodecPlayer* player) { | |
| 27 player->SetState(StatePaused::Instance()); | |
| 28 player->ReleaseDecoderResources(); | |
| 29 } | |
| 30 | |
|
qinmin
2015/05/13 23:17:32
ditto
Tima Vaisburd
2015/05/14 00:14:59
I put 2 lines between different states, e.g. the m
| |
| 31 | |
| 32 // StatePaused | |
| 33 | |
| 34 void StatePaused::EventStart(MediaCodecPlayer* player) { | |
| 35 player->SetState(StatePrefetching::Instance()); | |
| 36 player->StartPrefetchDecoders(); | |
| 37 } | |
| 38 | |
|
qinmin
2015/05/13 23:17:32
ditto
| |
| 39 | |
| 40 // StatePrefetching | |
| 41 | |
| 42 void StatePrefetching::EventPause(MediaCodecPlayer* player) { | |
| 43 player->SetState(StatePaused::Instance()); | |
| 44 player->StopDecoders(); | |
| 45 } | |
| 46 | |
| 47 void StatePrefetching::EventPrefetchDone(MediaCodecPlayer* player) { | |
| 48 if (!player->HasAudio() && !player->HasVideo()) { | |
| 49 // No configuration at all, let's wait for it. | |
| 50 // Although it probably should never happen here, | |
| 51 // after the data has come from demuxer. | |
| 52 player->SetState(StateWaitingForConfig::Instance()); | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 if (player->HasVideo() && !player->HasPendingSurface()) { | |
| 57 player->SetState(StateWaitingForSurface::Instance()); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 player->SetState(StatePlaying::Instance()); | |
| 62 player->StartPlaybackDecoders(); | |
| 63 } | |
| 64 | |
| 65 | |
| 66 // StateWaitingForConfig | |
| 67 | |
| 68 void StateWaitingForConfig::EventDemuxerConfigsAvailable( | |
| 69 MediaCodecPlayer* player, const DemuxerConfigs& configs) { | |
| 70 | |
| 71 player->SetDemuxerConfigs(configs); | |
| 72 | |
| 73 if (player->HasVideo() && !player->HasPendingSurface()) | |
| 74 { | |
|
qinmin
2015/05/13 23:17:32
{ has to go to the previous line
Tima Vaisburd
2015/05/14 00:14:59
Done.
| |
| 75 player->SetState(StateWaitingForSurface::Instance()); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 player->SetState(StatePlaying::Instance()); | |
| 80 player->StartPlaybackDecoders(); | |
| 81 } | |
| 82 | |
| 83 void StateWaitingForConfig::EventPause(MediaCodecPlayer* player) { | |
| 84 player->SetState(StatePaused::Instance()); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 // StateWaitingForSurface | |
| 89 | |
| 90 void StateWaitingForSurface::EventSetVideoSurface(MediaCodecPlayer* player) { | |
| 91 player->SetState(StatePlaying::Instance()); | |
| 92 player->StartPlaybackDecoders(); | |
| 93 } | |
| 94 | |
| 95 void StateWaitingForSurface::EventPause(MediaCodecPlayer* player) { | |
| 96 player->SetState(StatePaused::Instance()); | |
| 97 player->StopDecoders(); | |
| 98 } | |
| 99 | |
|
qinmin
2015/05/13 23:17:32
ditto
| |
| 100 | |
| 101 // StatePlaying | |
| 102 | |
| 103 void StatePlaying::EventPause(MediaCodecPlayer* player) { | |
| 104 player->SetState(StateStopping::Instance()); | |
| 105 player->RequestToStopDecoders(); | |
| 106 } | |
| 107 | |
| 108 void StatePlaying::EventStarvation(MediaCodecPlayer* player) { | |
| 109 player->SetState(StateStopping::Instance()); | |
| 110 player->RequestToStopDecoders(); | |
| 111 player->SetPendingStart(true); | |
| 112 } | |
| 113 | |
| 114 void StatePlaying::EventStopDone(MediaCodecPlayer* player) { | |
| 115 // Unexpected stop means completion | |
| 116 player->SetState(StatePaused::Instance()); | |
| 117 } | |
| 118 | |
| 119 void StatePlaying::EventError(MediaCodecPlayer* player) { | |
| 120 player->SetState(StateError::Instance()); | |
| 121 player->ReleaseDecoderResources(); | |
| 122 } | |
| 123 | |
|
qinmin
2015/05/13 23:17:32
ditto
| |
| 124 | |
| 125 // StateStopping | |
| 126 | |
| 127 void StateStopping::EventStart(MediaCodecPlayer* player) { | |
| 128 player->SetPendingStart(true); | |
| 129 } | |
| 130 | |
| 131 void StateStopping::EventStopDone(MediaCodecPlayer* player) { | |
| 132 if (player->HasPendingStart()) { | |
| 133 player->SetState(StatePrefetching::Instance()); | |
| 134 player->StartPrefetchDecoders(); | |
| 135 } else { | |
| 136 player->SetState(StatePaused::Instance()); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 } // namespace media | |
| OLD | NEW |