Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: webrtc/modules/audio_coding/codecs/audio_encoder_mutable_impl.h

Issue 1322973004: Fold AudioEncoderMutable into AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review fixes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 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
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_MUTABLE_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_MUTABLE_IMPL_H_
13
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/base/thread_annotations.h"
16 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18 #include "webrtc/system_wrappers/interface/thread_wrapper.h"
19
20 namespace webrtc {
21
22 // This is a convenient base class for implementations of AudioEncoderMutable.
23 // T is the type of the encoder state; it has to look like an AudioEncoder
24 // subclass whose constructor takes a single T::Config parameter. If P is
25 // given, this class will inherit from it instead of directly from
26 // AudioEncoderMutable.
27 template <typename T, typename P = AudioEncoderMutable>
28 class AudioEncoderMutableImpl : public P {
29 public:
30 void Reset() override {
31 typename T::Config config;
32 {
33 CriticalSectionScoped cs(encoder_lock_.get());
34 config = config_;
35 }
36 Reconstruct(config);
37 }
38
39 bool SetFec(bool enable) override { return false; }
40
41 bool SetDtx(bool enable) override { return false; }
42
43 bool SetApplication(AudioEncoderMutable::Application application) override {
44 return false;
45 }
46
47 void SetMaxPayloadSize(int max_payload_size_bytes) override {}
48
49 void SetMaxRate(int max_rate_bps) override {}
50
51 bool SetMaxPlaybackRate(int frequency_hz) override { return false; }
52
53 AudioEncoderMutable::EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
54 const int16_t* audio,
55 size_t max_encoded_bytes,
56 uint8_t* encoded) override {
57 CriticalSectionScoped cs(encoder_lock_.get());
58 return encoder_->EncodeInternal(rtp_timestamp, audio, max_encoded_bytes,
59 encoded);
60 }
61 int SampleRateHz() const override {
62 CriticalSectionScoped cs(encoder_lock_.get());
63 return encoder_->SampleRateHz();
64 }
65 int NumChannels() const override {
66 CriticalSectionScoped cs(encoder_lock_.get());
67 return encoder_->NumChannels();
68 }
69 size_t MaxEncodedBytes() const override {
70 CriticalSectionScoped cs(encoder_lock_.get());
71 return encoder_->MaxEncodedBytes();
72 }
73 int RtpTimestampRateHz() const override {
74 CriticalSectionScoped cs(encoder_lock_.get());
75 return encoder_->RtpTimestampRateHz();
76 }
77 size_t Num10MsFramesInNextPacket() const override {
78 CriticalSectionScoped cs(encoder_lock_.get());
79 return encoder_->Num10MsFramesInNextPacket();
80 }
81 size_t Max10MsFramesInAPacket() const override {
82 CriticalSectionScoped cs(encoder_lock_.get());
83 return encoder_->Max10MsFramesInAPacket();
84 }
85 int GetTargetBitrate() const override {
86 CriticalSectionScoped cs(encoder_lock_.get());
87 return encoder_->GetTargetBitrate();
88 }
89 void SetTargetBitrate(int bits_per_second) override {
90 CriticalSectionScoped cs(encoder_lock_.get());
91 encoder_->SetTargetBitrate(bits_per_second);
92 }
93 void SetProjectedPacketLossRate(double fraction) override {
94 CriticalSectionScoped cs(encoder_lock_.get());
95 encoder_->SetProjectedPacketLossRate(fraction);
96 }
97
98 protected:
99 explicit AudioEncoderMutableImpl(const typename T::Config& config)
100 : encoder_lock_(CriticalSectionWrapper::CreateCriticalSection()) {
101 Reconstruct(config);
102 }
103
104 bool Reconstruct(const typename T::Config& config) {
105 if (!config.IsOk())
106 return false;
107 CriticalSectionScoped cs(encoder_lock_.get());
108 config_ = config;
109 encoder_.reset(new T(config_));
110 return true;
111 }
112
113 typename T::Config config() const {
114 CriticalSectionScoped cs(encoder_lock_.get());
115 return config_;
116 }
117 T* encoder() EXCLUSIVE_LOCKS_REQUIRED(encoder_lock_) {
118 return encoder_.get();
119 }
120 const T* encoder() const EXCLUSIVE_LOCKS_REQUIRED(encoder_lock_) {
121 return encoder_.get();
122 }
123
124 const rtc::scoped_ptr<CriticalSectionWrapper> encoder_lock_;
125
126 private:
127 rtc::scoped_ptr<T> encoder_ GUARDED_BY(encoder_lock_);
128 typename T::Config config_ GUARDED_BY(encoder_lock_);
129 };
130
131 } // namespace webrtc
132
133 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_MUTABLE_IMPL_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/audio_encoder.cc ('k') | webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698