OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | |
7 | |
8 #include "base/android/scoped_java_ref.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/threading/thread.h" | |
12 #include "media/base/android/demuxer_android.h" | |
13 #include "media/base/android/media_player_android.h" | |
14 #include "media/base/media_export.h" | |
15 #include "ui/gl/android/scoped_java_surface.h" | |
16 | |
17 namespace media { | |
18 | |
19 class BrowserCdm; | |
20 | |
21 // Returns the task runner for the media thread | |
22 MEDIA_EXPORT scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner(); | |
23 | |
24 | |
25 // This class implements the media player using Android's MediaCodec. | |
26 // It differs from MediaSourcePlayer in that it removes most | |
27 // processing away from UI thread: it uses a dedicated Media thread | |
28 // to receive the data and to handle commands. | |
29 class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid, | |
30 public DemuxerAndroidClient { | |
31 public: | |
32 // Constructs a player with the given ID and demuxer. |manager| must outlive | |
33 // the lifetime of this object. | |
34 MediaCodecPlayer(int player_id, | |
35 MediaPlayerManager* manager, | |
36 const RequestMediaResourcesCB& request_media_resources_cb, | |
37 scoped_ptr<DemuxerAndroid> demuxer, | |
38 const GURL& frame_url); | |
39 ~MediaCodecPlayer() override; | |
40 | |
41 // MediaPlayerAndroid implementation. | |
42 void DeleteOnCorrectThread() override; | |
43 void SetVideoSurface(gfx::ScopedJavaSurface surface) override; | |
44 void Start() override; | |
45 void Pause(bool is_media_related_action) override; | |
46 void SeekTo(base::TimeDelta timestamp) override; | |
47 void Release() override; | |
48 void SetVolume(double volume) override; | |
49 int GetVideoWidth() override; | |
50 int GetVideoHeight() override; | |
51 base::TimeDelta GetCurrentTime() override; | |
52 base::TimeDelta GetDuration() override; | |
53 bool IsPlaying() override; | |
54 bool CanPause() override; | |
55 bool CanSeekForward() override; | |
56 bool CanSeekBackward() override; | |
57 bool IsPlayerReady() override; | |
58 void SetCdm(BrowserCdm* cdm) override; | |
59 | |
60 // DemuxerAndroidClient implementation. | |
61 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; | |
62 void OnDemuxerDataAvailable(const DemuxerData& params) override; | |
63 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; | |
64 void OnDemuxerDurationChanged(base::TimeDelta duration) override; | |
65 | |
66 // Helper methods | |
67 void Initialize(); | |
68 void DestroySelf(); | |
69 | |
70 private: | |
71 // Object for posting tasks on UI thread. | |
72 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
73 | |
74 scoped_ptr<DemuxerAndroid> demuxer_; | |
75 | |
76 base::WeakPtr<MediaCodecPlayer> weak_this_; | |
77 // NOTE: Weak pointers must be invalidated before all other member variables. | |
78 base::WeakPtrFactory<MediaCodecPlayer> weak_factory_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | |
81 }; | |
82 | |
83 } // namespace media | |
84 | |
85 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | |
OLD | NEW |