blob: 508c2110a6b579f6f96adfed8bfec1ede52bbda9 [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
kwiberg5a25d952016-08-17 07:31:12 -070014#include <memory>
15
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010016#include "webrtc/common_types.h"
17#include "webrtc/engine_configurations.h"
18#include "webrtc/modules/include/module_common_types.h"
19#include "webrtc/typedefs.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020
21namespace webrtc {
kwiberg5a25d952016-08-17 07:31:12 -070022
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010023class FileCallback;
24
kwiberga06ce492016-08-16 05:35:24 -070025class FilePlayer {
26 public:
27 // The largest decoded frame size in samples (60ms with 32kHz sample rate).
28 enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 };
29 enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 };
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010030
kwiberga06ce492016-08-16 05:35:24 -070031 // Note: will return NULL for unsupported formats.
kwiberg5a25d952016-08-17 07:31:12 -070032 static std::unique_ptr<FilePlayer> NewFilePlayer(
33 const uint32_t instanceID,
34 const FileFormats fileFormat);
35
36 // Deprecated creation/destruction functions. Use NewFilePlayer instead.
kwiberga06ce492016-08-16 05:35:24 -070037 static FilePlayer* CreateFilePlayer(const uint32_t instanceID,
38 const FileFormats fileFormat);
kwiberga06ce492016-08-16 05:35:24 -070039 static void DestroyFilePlayer(FilePlayer* player);
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010040
kwiberg5a25d952016-08-17 07:31:12 -070041 virtual ~FilePlayer() = default;
42
kwiberga06ce492016-08-16 05:35:24 -070043 // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples|
44 // will be set to the number of samples read (not the number of samples per
45 // channel).
46 virtual int Get10msAudioFromFile(int16_t* outBuffer,
47 size_t& lengthInSamples,
48 int frequencyInHz) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010049
kwiberga06ce492016-08-16 05:35:24 -070050 // Register callback for receiving file playing notifications.
51 virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010052
kwiberga06ce492016-08-16 05:35:24 -070053 // API for playing audio from fileName to channel.
54 // Note: codecInst is used for pre-encoded files.
55 virtual int32_t StartPlayingFile(const char* fileName,
56 bool loop,
57 uint32_t startPosition,
58 float volumeScaling,
59 uint32_t notification,
kwibergd22854b2016-08-17 09:27:02 -070060 uint32_t stopPosition,
61 const CodecInst* codecInst) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010062
kwiberga06ce492016-08-16 05:35:24 -070063 // Note: codecInst is used for pre-encoded files.
64 virtual int32_t StartPlayingFile(InStream& sourceStream,
65 uint32_t startPosition,
66 float volumeScaling,
67 uint32_t notification,
kwibergd22854b2016-08-17 09:27:02 -070068 uint32_t stopPosition,
69 const CodecInst* codecInst) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010070
kwiberga06ce492016-08-16 05:35:24 -070071 virtual int32_t StopPlayingFile() = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010072
kwiberga06ce492016-08-16 05:35:24 -070073 virtual bool IsPlayingFile() const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010074
kwiberga06ce492016-08-16 05:35:24 -070075 virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010076
kwiberga06ce492016-08-16 05:35:24 -070077 // Set audioCodec to the currently used audio codec.
78 virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010079
kwiberga06ce492016-08-16 05:35:24 -070080 virtual int32_t Frequency() const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010081
kwiberga06ce492016-08-16 05:35:24 -070082 // Note: scaleFactor is in the range [0.0 - 2.0]
83 virtual int32_t SetAudioScaling(float scaleFactor) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010084};
85} // namespace webrtc
kwiberga06ce492016-08-16 05:35:24 -070086#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_