blob: 43ab5007dff2de754e680a98c66f0cbe4258a187 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +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
11#ifndef WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_
12#define WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_
13
14#include "common_types.h"
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000015#include "common_video/interface/i420_video_frame.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "engine_configurations.h"
17#include "module_common_types.h"
18#include "typedefs.h"
19
20namespace webrtc {
21class FileCallback;
22
23class FilePlayer
24{
25public:
26 // The largest decoded frame size in samples (60ms with 32kHz sample rate).
27 enum {MAX_AUDIO_BUFFER_IN_SAMPLES = 60*32};
28 enum {MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2};
29
30 // Note: will return NULL for video file formats (e.g. AVI) if the flag
31 // WEBRTC_MODULE_UTILITY_VIDEO is not defined.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000032 static FilePlayer* CreateFilePlayer(const uint32_t instanceID,
niklase@google.com470e71d2011-07-07 08:21:25 +000033 const FileFormats fileFormat);
34
35 static void DestroyFilePlayer(FilePlayer* player);
36
andrew@webrtc.orge59a0ac2012-05-08 17:12:40 +000037 // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples|
38 // will be set to the number of samples read (not the number of samples per
39 // channel).
40 virtual int Get10msAudioFromFile(
41 int16_t* outBuffer,
42 int& lengthInSamples,
43 int frequencyInHz) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45 // Register callback for receiving file playing notifications.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000046 virtual int32_t RegisterModuleFileCallback(
niklase@google.com470e71d2011-07-07 08:21:25 +000047 FileCallback* callback) = 0;
48
49 // API for playing audio from fileName to channel.
50 // Note: codecInst is used for pre-encoded files.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000051 virtual int32_t StartPlayingFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000052 const char* fileName,
niklase@google.com470e71d2011-07-07 08:21:25 +000053 bool loop,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000054 uint32_t startPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +000055 float volumeScaling,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000056 uint32_t notification,
57 uint32_t stopPosition = 0,
niklase@google.com470e71d2011-07-07 08:21:25 +000058 const CodecInst* codecInst = NULL) = 0;
59
60 // Note: codecInst is used for pre-encoded files.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000061 virtual int32_t StartPlayingFile(
niklase@google.com470e71d2011-07-07 08:21:25 +000062 InStream& sourceStream,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000063 uint32_t startPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +000064 float volumeScaling,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000065 uint32_t notification,
66 uint32_t stopPosition = 0,
niklase@google.com470e71d2011-07-07 08:21:25 +000067 const CodecInst* codecInst = NULL) = 0;
68
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000069 virtual int32_t StopPlayingFile() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
71 virtual bool IsPlayingFile() const = 0;
72
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000073 virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000074
75 // Set audioCodec to the currently used audio codec.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000076 virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000078 virtual int32_t Frequency() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
80 // Note: scaleFactor is in the range [0.0 - 2.0]
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000081 virtual int32_t SetAudioScaling(float scaleFactor) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
83 // Return the time in ms until next video frame should be pulled (by
84 // calling GetVideoFromFile(..)).
85 // Note: this API reads one video frame from file. This means that it should
86 // be called exactly once per GetVideoFromFile(..) API call.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000087 virtual int32_t TimeUntilNextVideoFrame() { return -1;}
niklase@google.com470e71d2011-07-07 08:21:25 +000088
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000089 virtual int32_t StartPlayingVideoFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000090 const char* /*fileName*/,
niklase@google.com470e71d2011-07-07 08:21:25 +000091 bool /*loop*/,
92 bool /*videoOnly*/) { return -1;}
93
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000094 virtual int32_t video_codec_info(VideoCodec& /*videoCodec*/) const
niklase@google.com470e71d2011-07-07 08:21:25 +000095 {return -1;}
96
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000097 virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/)
niklase@google.com470e71d2011-07-07 08:21:25 +000098 { return -1;}
99
100 // Same as GetVideoFromFile(). videoFrame will have the resolution specified
101 // by the width outWidth and height outHeight in pixels.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +0000102 virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/,
103 const uint32_t /*outWidth*/,
104 const uint32_t /*outHeight*/)
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 {return -1;}
106protected:
107 virtual ~FilePlayer() {}
108
109};
110} // namespace webrtc
111#endif // WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_