blob: 5b7af49c0597ce77097a146b75421dc6856a5fbc [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.
32 static FilePlayer* CreateFilePlayer(const WebRtc_UWord32 instanceID,
33 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.
46 virtual WebRtc_Word32 RegisterModuleFileCallback(
47 FileCallback* callback) = 0;
48
49 // API for playing audio from fileName to channel.
50 // Note: codecInst is used for pre-encoded files.
51 virtual WebRtc_Word32 StartPlayingFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000052 const char* fileName,
niklase@google.com470e71d2011-07-07 08:21:25 +000053 bool loop,
54 WebRtc_UWord32 startPosition,
55 float volumeScaling,
56 WebRtc_UWord32 notification,
57 WebRtc_UWord32 stopPosition = 0,
58 const CodecInst* codecInst = NULL) = 0;
59
60 // Note: codecInst is used for pre-encoded files.
61 virtual WebRtc_Word32 StartPlayingFile(
62 InStream& sourceStream,
63 WebRtc_UWord32 startPosition,
64 float volumeScaling,
65 WebRtc_UWord32 notification,
66 WebRtc_UWord32 stopPosition = 0,
67 const CodecInst* codecInst = NULL) = 0;
68
69 virtual WebRtc_Word32 StopPlayingFile() = 0;
70
71 virtual bool IsPlayingFile() const = 0;
72
73 virtual WebRtc_Word32 GetPlayoutPosition(WebRtc_UWord32& durationMs) = 0;
74
75 // Set audioCodec to the currently used audio codec.
76 virtual WebRtc_Word32 AudioCodec(CodecInst& audioCodec) const = 0;
77
78 virtual WebRtc_Word32 Frequency() const = 0;
79
80 // Note: scaleFactor is in the range [0.0 - 2.0]
81 virtual WebRtc_Word32 SetAudioScaling(float scaleFactor) = 0;
82
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.
87 virtual WebRtc_Word32 TimeUntilNextVideoFrame() { return -1;}
88
89 virtual WebRtc_Word32 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
94 virtual WebRtc_Word32 video_codec_info(VideoCodec& /*videoCodec*/) const
95 {return -1;}
96
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000097 virtual WebRtc_Word32 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.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000102 virtual WebRtc_Word32 GetVideoFromFile(I420VideoFrame& /*videoFrame*/,
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 const WebRtc_UWord32 /*outWidth*/,
104 const WebRtc_UWord32 /*outHeight*/)
105 {return -1;}
106protected:
107 virtual ~FilePlayer() {}
108
109};
110} // namespace webrtc
111#endif // WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_