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

Side by Side Diff: remoting/codec/audio_decoder_speex.cc

Issue 16964002: Rewrite scoped_ptr<T>(NULL) to use the default ctor in remoting/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/codec/audio_decoder_speex.h" 5 #include "remoting/codec/audio_decoder_speex.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 speex_bits_destroy(speex_bits_.get()); 67 speex_bits_destroy(speex_bits_.get());
68 } 68 }
69 69
70 scoped_ptr<AudioPacket> AudioDecoderSpeex::Decode( 70 scoped_ptr<AudioPacket> AudioDecoderSpeex::Decode(
71 scoped_ptr<AudioPacket> packet) { 71 scoped_ptr<AudioPacket> packet) {
72 if ((packet->encoding() != AudioPacket::ENCODING_SPEEX) || 72 if ((packet->encoding() != AudioPacket::ENCODING_SPEEX) ||
73 (packet->bytes_per_sample() != AudioPacket::BYTES_PER_SAMPLE_2) || 73 (packet->bytes_per_sample() != AudioPacket::BYTES_PER_SAMPLE_2) ||
74 (packet->sampling_rate() == AudioPacket::SAMPLING_RATE_INVALID) || 74 (packet->sampling_rate() == AudioPacket::SAMPLING_RATE_INVALID) ||
75 (packet->channels() != AudioPacket::CHANNELS_STEREO)) { 75 (packet->channels() != AudioPacket::CHANNELS_STEREO)) {
76 LOG(WARNING) << "Received an unsupported packet."; 76 LOG(WARNING) << "Received an unsupported packet.";
77 return scoped_ptr<AudioPacket>(NULL); 77 return scoped_ptr<AudioPacket>();
78 } 78 }
79 if (packet->data_size() > kMaxFramesPerPacket) { 79 if (packet->data_size() > kMaxFramesPerPacket) {
80 LOG(WARNING) << "Received an packet with too many frames."; 80 LOG(WARNING) << "Received an packet with too many frames.";
81 return scoped_ptr<AudioPacket>(); 81 return scoped_ptr<AudioPacket>();
82 } 82 }
83 83
84 // Create a new packet of decoded data. 84 // Create a new packet of decoded data.
85 scoped_ptr<AudioPacket> decoded_packet(new AudioPacket()); 85 scoped_ptr<AudioPacket> decoded_packet(new AudioPacket());
86 decoded_packet->set_encoding(AudioPacket::ENCODING_RAW); 86 decoded_packet->set_encoding(AudioPacket::ENCODING_RAW);
87 decoded_packet->set_sampling_rate(packet->sampling_rate()); 87 decoded_packet->set_sampling_rate(packet->sampling_rate());
(...skipping 10 matching lines...) Expand all
98 for (int i = 0; i < packet->data_size(); ++i) { 98 for (int i = 0; i < packet->data_size(); ++i) {
99 // Read the bytes into the bits structure. 99 // Read the bytes into the bits structure.
100 speex_bits_read_from(speex_bits_.get(), 100 speex_bits_read_from(speex_bits_.get(),
101 string_as_array(packet->mutable_data(i)), 101 string_as_array(packet->mutable_data(i)),
102 packet->data(i).size()); 102 packet->data(i).size());
103 103
104 // Decode the frame and store it in the buffer. 104 // Decode the frame and store it in the buffer.
105 int status = speex_decode_int(speex_state_, speex_bits_.get(), samples); 105 int status = speex_decode_int(speex_state_, speex_bits_.get(), samples);
106 if (status < 0) { 106 if (status < 0) {
107 LOG(ERROR) << "Error in decoding Speex data."; 107 LOG(ERROR) << "Error in decoding Speex data.";
108 return scoped_ptr<AudioPacket>(NULL); 108 return scoped_ptr<AudioPacket>();
109 } 109 }
110 // Transform mono to stereo. 110 // Transform mono to stereo.
111 speex_decode_stereo_int(samples, speex_frame_size_, speex_stereo_state_); 111 speex_decode_stereo_int(samples, speex_frame_size_, speex_stereo_state_);
112 112
113 samples += (speex_frame_size_ * packet->channels()); 113 samples += (speex_frame_size_ * packet->channels());
114 } 114 }
115 115
116 return decoded_packet.Pass(); 116 return decoded_packet.Pass();
117 } 117 }
118 118
119 } // namespace remoting 119 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698