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 | |
| 9 // MediaCodecPlayerState (superclass) | |
| 10 | |
| 11 // By default, set configs for the future use | |
| 12 void MediaCodecPlayerState::EventDemuxerConfigsAvailable( | |
| 13 MediaCodecPlayer* player, const DemuxerConfigs& configs) { | |
| 14 player->SetDemuxerConfigs(configs); | |
| 15 } | |
| 16 | |
| 17 // By default, set the Error state that blocks all events | |
| 18 void MediaCodecPlayerState::EventError(MediaCodecPlayer* player) { | |
| 19 player->SetState(StateError::Instance()); | |
| 20 } | |
| 21 | |
| 22 // Stop decoders synchronously. | |
| 23 // TODO: as it seems to work for every state, consider moving Release() | |
| 24 // out of the state machine. | |
| 25 void MediaCodecPlayerState::EventRelease(MediaCodecPlayer* player) { | |
| 26 player->SetState(StatePaused::Instance()); | |
| 27 player->ReleaseDecoderResources(); | |
| 28 } | |
| 29 | |
| 30 | |
| 31 // StatePaused | |
| 32 | |
| 33 void StatePaused::EventStart(MediaCodecPlayer* player) { | |
| 34 player->SetState(StatePrefetching::Instance()); | |
| 35 player->StartPrefetchDecoders(); | |
| 36 } | |
| 37 | |
| 38 | |
| 39 // StatePrefetching | |
| 40 | |
| 41 void StatePrefetching::EventPause(MediaCodecPlayer* player) { | |
| 42 player->SetState(StatePaused::Instance()); | |
|
qinmin
2015/05/14 19:52:58
I have bad feelings about these call sequences, an
Tima Vaisburd
2015/05/15 00:12:40
Yes, it does look somewhat weird. The code like
| |
| 43 player->StopDecoders(); | |
| 44 } | |
| 45 | |
| 46 void StatePrefetching::EventPrefetchDone(MediaCodecPlayer* player) { | |
| 47 if (!player->HasAudio() && !player->HasVideo()) { | |
| 48 // No configuration at all, let's wait for it. | |
| 49 // Although it probably should never happen here, | |
| 50 // after the data has come from demuxer. | |
| 51 player->SetState(StateWaitingForConfig::Instance()); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 if (player->HasVideo() && !player->HasPendingSurface()) { | |
| 56 player->SetState(StateWaitingForSurface::Instance()); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 player->SetState(StatePlaying::Instance()); | |
| 61 player->StartPlaybackDecoders(); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 // StateWaitingForConfig | |
| 66 | |
| 67 void StateWaitingForConfig::EventDemuxerConfigsAvailable( | |
| 68 MediaCodecPlayer* player, const DemuxerConfigs& configs) { | |
| 69 | |
| 70 player->SetDemuxerConfigs(configs); | |
| 71 | |
| 72 if (player->HasVideo() && !player->HasPendingSurface()) { | |
| 73 player->SetState(StateWaitingForSurface::Instance()); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 player->SetState(StatePlaying::Instance()); | |
| 78 player->StartPlaybackDecoders(); | |
| 79 } | |
| 80 | |
| 81 void StateWaitingForConfig::EventPause(MediaCodecPlayer* player) { | |
| 82 player->SetState(StatePaused::Instance()); | |
| 83 } | |
| 84 | |
| 85 | |
| 86 // StateWaitingForSurface | |
| 87 | |
| 88 void StateWaitingForSurface::EventSetVideoSurface(MediaCodecPlayer* player) { | |
| 89 player->SetState(StatePlaying::Instance()); | |
| 90 player->StartPlaybackDecoders(); | |
| 91 } | |
| 92 | |
| 93 void StateWaitingForSurface::EventPause(MediaCodecPlayer* player) { | |
| 94 player->SetState(StatePaused::Instance()); | |
| 95 player->StopDecoders(); | |
| 96 } | |
| 97 | |
| 98 | |
| 99 // StatePlaying | |
| 100 | |
| 101 void StatePlaying::EventPause(MediaCodecPlayer* player) { | |
| 102 player->SetState(StateStopping::Instance()); | |
| 103 player->RequestToStopDecoders(); | |
| 104 } | |
| 105 | |
| 106 void StatePlaying::EventStarvation(MediaCodecPlayer* player) { | |
| 107 player->SetState(StateStopping::Instance()); | |
| 108 player->RequestToStopDecoders(); | |
| 109 player->SetPendingStart(true); | |
| 110 } | |
| 111 | |
| 112 void StatePlaying::EventStopDone(MediaCodecPlayer* player) { | |
| 113 // Unexpected stop means completion | |
| 114 player->SetState(StatePaused::Instance()); | |
| 115 } | |
| 116 | |
| 117 void StatePlaying::EventError(MediaCodecPlayer* player) { | |
| 118 player->SetState(StateError::Instance()); | |
| 119 player->ReleaseDecoderResources(); | |
| 120 } | |
| 121 | |
| 122 | |
| 123 // StateStopping | |
| 124 | |
| 125 void StateStopping::EventStart(MediaCodecPlayer* player) { | |
| 126 player->SetPendingStart(true); | |
| 127 } | |
| 128 | |
| 129 void StateStopping::EventStopDone(MediaCodecPlayer* player) { | |
| 130 if (player->HasPendingStart()) { | |
| 131 player->SetState(StatePrefetching::Instance()); | |
| 132 player->StartPrefetchDecoders(); | |
| 133 } else { | |
| 134 player->SetState(StatePaused::Instance()); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 } // namespace media | |
| OLD | NEW |