blob: ee7be64dd9c6a7bf98335d772fc1d5148c037a4a [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"
15#include "engine_configurations.h"
16#include "module_common_types.h"
17#include "typedefs.h"
18
19namespace webrtc {
20class FileCallback;
21
22class FilePlayer
23{
24public:
25 // The largest decoded frame size in samples (60ms with 32kHz sample rate).
26 enum {MAX_AUDIO_BUFFER_IN_SAMPLES = 60*32};
27 enum {MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2};
28
29 // Note: will return NULL for video file formats (e.g. AVI) if the flag
30 // WEBRTC_MODULE_UTILITY_VIDEO is not defined.
31 static FilePlayer* CreateFilePlayer(const WebRtc_UWord32 instanceID,
32 const FileFormats fileFormat);
33
34 static void DestroyFilePlayer(FilePlayer* player);
35
andrew@webrtc.orge59a0ac2012-05-08 17:12:40 +000036 // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples|
37 // will be set to the number of samples read (not the number of samples per
38 // channel).
39 virtual int Get10msAudioFromFile(
40 int16_t* outBuffer,
41 int& lengthInSamples,
42 int frequencyInHz) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000043
44 // Register callback for receiving file playing notifications.
45 virtual WebRtc_Word32 RegisterModuleFileCallback(
46 FileCallback* callback) = 0;
47
48 // API for playing audio from fileName to channel.
49 // Note: codecInst is used for pre-encoded files.
50 virtual WebRtc_Word32 StartPlayingFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000051 const char* fileName,
niklase@google.com470e71d2011-07-07 08:21:25 +000052 bool loop,
53 WebRtc_UWord32 startPosition,
54 float volumeScaling,
55 WebRtc_UWord32 notification,
56 WebRtc_UWord32 stopPosition = 0,
57 const CodecInst* codecInst = NULL) = 0;
58
59 // Note: codecInst is used for pre-encoded files.
60 virtual WebRtc_Word32 StartPlayingFile(
61 InStream& sourceStream,
62 WebRtc_UWord32 startPosition,
63 float volumeScaling,
64 WebRtc_UWord32 notification,
65 WebRtc_UWord32 stopPosition = 0,
66 const CodecInst* codecInst = NULL) = 0;
67
68 virtual WebRtc_Word32 StopPlayingFile() = 0;
69
70 virtual bool IsPlayingFile() const = 0;
71
72 virtual WebRtc_Word32 GetPlayoutPosition(WebRtc_UWord32& durationMs) = 0;
73
74 // Set audioCodec to the currently used audio codec.
75 virtual WebRtc_Word32 AudioCodec(CodecInst& audioCodec) const = 0;
76
77 virtual WebRtc_Word32 Frequency() const = 0;
78
79 // Note: scaleFactor is in the range [0.0 - 2.0]
80 virtual WebRtc_Word32 SetAudioScaling(float scaleFactor) = 0;
81
82 // Return the time in ms until next video frame should be pulled (by
83 // calling GetVideoFromFile(..)).
84 // Note: this API reads one video frame from file. This means that it should
85 // be called exactly once per GetVideoFromFile(..) API call.
86 virtual WebRtc_Word32 TimeUntilNextVideoFrame() { return -1;}
87
88 virtual WebRtc_Word32 StartPlayingVideoFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000089 const char* /*fileName*/,
niklase@google.com470e71d2011-07-07 08:21:25 +000090 bool /*loop*/,
91 bool /*videoOnly*/) { return -1;}
92
93 virtual WebRtc_Word32 video_codec_info(VideoCodec& /*videoCodec*/) const
94 {return -1;}
95
96 virtual WebRtc_Word32 GetVideoFromFile(VideoFrame& /*videoFrame*/)
97 { return -1;}
98
99 // Same as GetVideoFromFile(). videoFrame will have the resolution specified
100 // by the width outWidth and height outHeight in pixels.
101 virtual WebRtc_Word32 GetVideoFromFile(VideoFrame& /*videoFrame*/,
102 const WebRtc_UWord32 /*outWidth*/,
103 const WebRtc_UWord32 /*outHeight*/)
104 {return -1;}
105protected:
106 virtual ~FilePlayer() {}
107
108};
109} // namespace webrtc
110#endif // WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_