blob: 37e1d20188b62f993ca1b4664268c9adbff3ae29 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org39e96592012-03-01 18:22:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orge06ca3c2012-06-29 13:20:14 +000011#ifndef WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
mflodman@webrtc.org70111e62012-01-19 12:48:53 +000014#include <list>
15#include <set>
16
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000017#include "common_types.h" // NOLINT
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000018#include "common_video/interface/i420_video_frame.h"
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000019#include "modules/media_file/interface/media_file_defines.h"
20#include "system_wrappers/interface/file_wrapper.h"
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000021#include "typedefs.h" // NOLINT
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000022#include "video_engine/vie_frame_provider_base.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000024namespace webrtc {
25
niklase@google.com470e71d2011-07-07 08:21:25 +000026class EventWrapper;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000027class FilePlayer;
niklase@google.com470e71d2011-07-07 08:21:25 +000028class ThreadWrapper;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000029class ViEFileObserver;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000030class VoEFile;
31class VoEVideoSync;
32class VoiceEngine;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000034class 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.org7991c052011-12-14 08:38:37 +000044 VoiceEngine* voe_ptr);
niklase@google.com470e71d2011-07-07 08:21:25 +000045
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000046 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.com470e71d2011-07-07 08:21:25 +000052
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000053 bool IsObserverRegistered();
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000054 int RegisterObserver(ViEFileObserver* observer);
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000055 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.com470e71d2011-07-07 08:21:25 +000062
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000063 // Implements ViEFrameProviderBase.
64 virtual int FrameCallbackChanged();
niklase@google.com470e71d2011-07-07 08:21:25 +000065
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000066 protected:
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000067 ViEFilePlayer(int Id, int engine_id);
leozwang@webrtc.org39e96592012-03-01 18:22:48 +000068 int Init(const char* file_nameUTF8,
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000069 const bool loop,
70 const FileFormats file_format,
71 VoiceEngine* voe_ptr);
72 int StopPlay();
73 int StopPlayAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000074
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000075 // File play decode function.
76 static bool FilePlayDecodeThreadFunction(void* obj);
77 bool FilePlayDecodeProcess();
78 bool NeedsAudioFromFile(void* buf);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000080 // Implements webrtc::InStream.
81 virtual int Read(void* buf, int len);
82 virtual int Rewind() {
83 return 0;
84 }
niklase@google.com470e71d2011-07-07 08:21:25 +000085
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000086 // Implements FileCallback.
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000087 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.com470e71d2011-07-07 08:21:25 +000093
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000094 private:
mflodman@webrtc.orgba09cf12012-01-24 07:49:33 +000095 static const int kMaxDecodedAudioLength = 320;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000096 bool play_back_started_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097
mflodman@webrtc.org7991c052011-12-14 08:38:37 +000098 CriticalSectionWrapper* feedback_cs_;
99 CriticalSectionWrapper* audio_cs_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000101 FilePlayer* file_player_;
102 bool audio_stream_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000104 // Number of active video clients.
105 int video_clients_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000107 // Number of audio channels sending this audio.
108 int audio_clients_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000110 // Local audio channel playing this video. Sync video against this.
111 int local_audio_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000113 ViEFileObserver* observer_;
leozwang@webrtc.org39e96592012-03-01 18:22:48 +0000114 char file_name_[FileWrapper::kMaxFileNameSize];
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000116 // 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.orgb238d122013-04-09 13:41:51 +0000123 int16_t decoded_audio_[kMaxDecodedAudioLength];
andrew@webrtc.orge59a0ac2012-05-08 17:12:40 +0000124 int decoded_audio_length_;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000125
126 // Trick - list containing VoE buffer reading this file. Used if multiple
127 // audio channels are sending.
mflodman@webrtc.org70111e62012-01-19 12:48:53 +0000128 std::list<void*> audio_channel_buffers_;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000129
130 // AudioChannels sending audio from this file.
mflodman@webrtc.org70111e62012-01-19 12:48:53 +0000131 std::set<int> audio_channels_sending_;
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000132
133 // Frame receiving decoded video from file.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000134 I420VideoFrame decoded_video_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135};
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
mflodman@webrtc.org7991c052011-12-14 08:38:37 +0000137} // namespace webrtc
138
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +0000139#endif // WEBRTC_VIDEO_ENGINE_VIE_FILE_PLAYER_H_