blob: d11261de869733971b291ea9106894ad59dfca1b [file] [log] [blame]
Henrik Kjellanderff761fb2015-11-04 08:31:52 +01001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
kwiberg9d7eb132016-08-16 04:08:30 -070011#ifndef WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_
12#define WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010013
14#include "webrtc/common_types.h"
15#include "webrtc/engine_configurations.h"
16#include "webrtc/modules/include/module_common_types.h"
17#include "webrtc/typedefs.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010018
19namespace webrtc {
20class FileCallback;
21
kwiberga06ce492016-08-16 05:35:24 -070022class FilePlayer {
23 public:
24 // The largest decoded frame size in samples (60ms with 32kHz sample rate).
25 enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 };
26 enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 };
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010027
kwiberga06ce492016-08-16 05:35:24 -070028 // Note: will return NULL for unsupported formats.
29 static FilePlayer* CreateFilePlayer(const uint32_t instanceID,
30 const FileFormats fileFormat);
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010031
kwiberga06ce492016-08-16 05:35:24 -070032 static void DestroyFilePlayer(FilePlayer* player);
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010033
kwiberga06ce492016-08-16 05:35:24 -070034 // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples|
35 // will be set to the number of samples read (not the number of samples per
36 // channel).
37 virtual int Get10msAudioFromFile(int16_t* outBuffer,
38 size_t& lengthInSamples,
39 int frequencyInHz) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010040
kwiberga06ce492016-08-16 05:35:24 -070041 // Register callback for receiving file playing notifications.
42 virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010043
kwiberga06ce492016-08-16 05:35:24 -070044 // API for playing audio from fileName to channel.
45 // Note: codecInst is used for pre-encoded files.
46 virtual int32_t StartPlayingFile(const char* fileName,
47 bool loop,
48 uint32_t startPosition,
49 float volumeScaling,
50 uint32_t notification,
51 uint32_t stopPosition = 0,
52 const CodecInst* codecInst = NULL) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010053
kwiberga06ce492016-08-16 05:35:24 -070054 // Note: codecInst is used for pre-encoded files.
55 virtual int32_t StartPlayingFile(InStream& sourceStream,
56 uint32_t startPosition,
57 float volumeScaling,
58 uint32_t notification,
59 uint32_t stopPosition = 0,
60 const CodecInst* codecInst = NULL) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010061
kwiberga06ce492016-08-16 05:35:24 -070062 virtual int32_t StopPlayingFile() = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010063
kwiberga06ce492016-08-16 05:35:24 -070064 virtual bool IsPlayingFile() const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010065
kwiberga06ce492016-08-16 05:35:24 -070066 virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010067
kwiberga06ce492016-08-16 05:35:24 -070068 // Set audioCodec to the currently used audio codec.
69 virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010070
kwiberga06ce492016-08-16 05:35:24 -070071 virtual int32_t Frequency() const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010072
kwiberga06ce492016-08-16 05:35:24 -070073 // Note: scaleFactor is in the range [0.0 - 2.0]
74 virtual int32_t SetAudioScaling(float scaleFactor) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010075
kwiberga06ce492016-08-16 05:35:24 -070076 protected:
77 virtual ~FilePlayer() {}
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010078};
79} // namespace webrtc
kwiberga06ce492016-08-16 05:35:24 -070080#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_