niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 39e9659 | 2012-03-01 18:22:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
mflodman@webrtc.org | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
mflodman@webrtc.org | 70111e6 | 2012-01-19 12:48:53 +0000 | [diff] [blame] | 14 | #include <list> |
| 15 | #include <set> |
| 16 | |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 17 | #include "common_types.h" // NOLINT |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 18 | #include "common_video/interface/i420_video_frame.h" |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 19 | #include "modules/media_file/interface/media_file_defines.h" |
| 20 | #include "system_wrappers/interface/file_wrapper.h" |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 21 | #include "typedefs.h" // NOLINT |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 22 | #include "video_engine/vie_frame_provider_base.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | class EventWrapper; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 27 | class FilePlayer; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | class ThreadWrapper; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 29 | class ViEFileObserver; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 30 | class VoEFile; |
| 31 | class VoEVideoSync; |
| 32 | class VoiceEngine; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 34 | class ViEFilePlayer |
| 35 | : public ViEFrameProviderBase, |
| 36 | protected FileCallback, |
| 37 | protected InStream { |
| 38 | public: |
| 39 | static ViEFilePlayer* CreateViEFilePlayer(int file_id, |
| 40 | int engine_id, |
| 41 | const char* file_nameUTF8, |
| 42 | const bool loop, |
| 43 | const FileFormats file_format, |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 44 | VoiceEngine* voe_ptr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 46 | static int GetFileInformation(const int engine_id, |
| 47 | const char* file_name, |
| 48 | VideoCodec& video_codec, |
| 49 | CodecInst& audio_codec, |
| 50 | const FileFormats file_format); |
| 51 | ~ViEFilePlayer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 53 | bool IsObserverRegistered(); |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 54 | int RegisterObserver(ViEFileObserver* observer); |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 55 | int DeRegisterObserver(); |
| 56 | int SendAudioOnChannel(const int audio_channel, |
| 57 | bool mix_microphone, |
| 58 | float volume_scaling); |
| 59 | int StopSendAudioOnChannel(const int audio_channel); |
| 60 | int PlayAudioLocally(const int audio_channel, float volume_scaling); |
| 61 | int StopPlayAudioLocally(const int audio_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 63 | // Implements ViEFrameProviderBase. |
| 64 | virtual int FrameCallbackChanged(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 66 | protected: |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 67 | ViEFilePlayer(int Id, int engine_id); |
leozwang@webrtc.org | 39e9659 | 2012-03-01 18:22:48 +0000 | [diff] [blame] | 68 | int Init(const char* file_nameUTF8, |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 69 | const bool loop, |
| 70 | const FileFormats file_format, |
| 71 | VoiceEngine* voe_ptr); |
| 72 | int StopPlay(); |
| 73 | int StopPlayAudio(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 75 | // File play decode function. |
| 76 | static bool FilePlayDecodeThreadFunction(void* obj); |
| 77 | bool FilePlayDecodeProcess(); |
| 78 | bool NeedsAudioFromFile(void* buf); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 80 | // Implements webrtc::InStream. |
| 81 | virtual int Read(void* buf, int len); |
| 82 | virtual int Rewind() { |
| 83 | return 0; |
| 84 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 86 | // Implements FileCallback. |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 87 | virtual void PlayNotification(const int32_t /*id*/, |
| 88 | const uint32_t /*notification_ms*/) {} |
| 89 | virtual void RecordNotification(const int32_t /*id*/, |
| 90 | const uint32_t /*notification_ms*/) {} |
| 91 | virtual void PlayFileEnded(const int32_t id); |
| 92 | virtual void RecordFileEnded(const int32_t /*id*/) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 94 | private: |
mflodman@webrtc.org | ba09cf1 | 2012-01-24 07:49:33 +0000 | [diff] [blame] | 95 | static const int kMaxDecodedAudioLength = 320; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 96 | bool play_back_started_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 98 | CriticalSectionWrapper* feedback_cs_; |
| 99 | CriticalSectionWrapper* audio_cs_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 101 | FilePlayer* file_player_; |
| 102 | bool audio_stream_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 104 | // Number of active video clients. |
| 105 | int video_clients_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 107 | // Number of audio channels sending this audio. |
| 108 | int audio_clients_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 110 | // Local audio channel playing this video. Sync video against this. |
| 111 | int local_audio_channel_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 113 | ViEFileObserver* observer_; |
leozwang@webrtc.org | 39e9659 | 2012-03-01 18:22:48 +0000 | [diff] [blame] | 114 | char file_name_[FileWrapper::kMaxFileNameSize]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 116 | // VoE Interface. |
| 117 | VoEFile* voe_file_interface_; |
| 118 | VoEVideoSync* voe_video_sync_; |
| 119 | |
| 120 | // Thread for decoding video (and audio if no audio clients connected). |
| 121 | ThreadWrapper* decode_thread_; |
| 122 | EventWrapper* decode_event_; |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 123 | int16_t decoded_audio_[kMaxDecodedAudioLength]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 124 | int decoded_audio_length_; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 125 | |
| 126 | // Trick - list containing VoE buffer reading this file. Used if multiple |
| 127 | // audio channels are sending. |
mflodman@webrtc.org | 70111e6 | 2012-01-19 12:48:53 +0000 | [diff] [blame] | 128 | std::list<void*> audio_channel_buffers_; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 129 | |
| 130 | // AudioChannels sending audio from this file. |
mflodman@webrtc.org | 70111e6 | 2012-01-19 12:48:53 +0000 | [diff] [blame] | 131 | std::set<int> audio_channels_sending_; |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 132 | |
| 133 | // Frame receiving decoded video from file. |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 134 | I420VideoFrame decoded_video_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
mflodman@webrtc.org | 7991c05 | 2011-12-14 08:38:37 +0000 | [diff] [blame] | 137 | } // namespace webrtc |
| 138 | |
mflodman@webrtc.org | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 139 | #endif // WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_ |