OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 11 #ifndef WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
12 #define WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 12 #define WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
13 | 13 |
14 #include <assert.h> | 14 #include <assert.h> |
15 #include <string.h> // memcpy | 15 #include <string.h> // memcpy |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <limits> | 18 #include <limits> |
19 | 19 |
20 #include "webrtc/api/optional.h" | 20 #include "webrtc/api/optional.h" |
21 #include "webrtc/api/video/video_rotation.h" | 21 #include "webrtc/api/video/video_rotation.h" |
22 #include "webrtc/common_types.h" | 22 #include "webrtc/common_types.h" |
23 #include "webrtc/modules/video_coding/codecs/h264/include/h264_globals.h" | 23 #include "webrtc/modules/video_coding/codecs/h264/include/h264_globals.h" |
24 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_globals.h" | 24 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_globals.h" |
25 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" | 25 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" |
26 #include "webrtc/rtc_base/constructormagic.h" | 26 #include "webrtc/rtc_base/constructormagic.h" |
27 #include "webrtc/rtc_base/deprecation.h" | 27 #include "webrtc/rtc_base/deprecation.h" |
28 #include "webrtc/rtc_base/safe_conversions.h" | 28 #include "webrtc/rtc_base/safe_conversions.h" |
29 #include "webrtc/rtc_base/timeutils.h" | |
29 #include "webrtc/typedefs.h" | 30 #include "webrtc/typedefs.h" |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 | 33 |
33 struct RTPAudioHeader { | 34 struct RTPAudioHeader { |
34 uint8_t numEnergy; // number of valid entries in arrOfEnergy | 35 uint8_t numEnergy; // number of valid entries in arrOfEnergy |
35 uint8_t arrOfEnergy[kRtpCsrcSize]; // one energy byte (0-9) per channel | 36 uint8_t arrOfEnergy[kRtpCsrcSize]; // one energy byte (0-9) per channel |
36 bool isCNG; // is this CNG | 37 bool isCNG; // is this CNG |
37 size_t channel; // number of channels 2 = stereo | 38 size_t channel; // number of channels 2 = stereo |
38 }; | 39 }; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 // ResetWithoutMuting() to skip this wasteful zeroing. | 330 // ResetWithoutMuting() to skip this wasteful zeroing. |
330 void ResetWithoutMuting(); | 331 void ResetWithoutMuting(); |
331 | 332 |
332 void UpdateFrame(int id, uint32_t timestamp, const int16_t* data, | 333 void UpdateFrame(int id, uint32_t timestamp, const int16_t* data, |
333 size_t samples_per_channel, int sample_rate_hz, | 334 size_t samples_per_channel, int sample_rate_hz, |
334 SpeechType speech_type, VADActivity vad_activity, | 335 SpeechType speech_type, VADActivity vad_activity, |
335 size_t num_channels = 1); | 336 size_t num_channels = 1); |
336 | 337 |
337 void CopyFrom(const AudioFrame& src); | 338 void CopyFrom(const AudioFrame& src); |
338 | 339 |
340 // Sets a wall-time clock timestamp in milliseconds to be used for profiling | |
341 // of time between two points in the audio chain. | |
342 // Example: | |
343 // t0: UpdateProfileTime() | |
344 // t1: TimeSinceLastProfile() => t1 - t0 [msec] | |
345 void UpdateProfileTime(); | |
hlundin-webrtc
2017/09/14 13:34:33
Suggest UpdateProfileTimestamp to match variable n
henrika_webrtc
2017/09/15 13:33:57
Done.
| |
346 // Returns the time difference between now and when UpdateProfileTime() was | |
347 // last called. Returns -1 if UpdateProfileTime() has not yet been called. | |
348 int64_t TimeSinceLastProfile() const; | |
hlundin-webrtc
2017/09/14 13:34:34
Suggest ElapsedProfileTimeMs().
henrika_webrtc
2017/09/15 13:33:57
Done.
| |
349 | |
339 // data() returns a zeroed static buffer if the frame is muted. | 350 // data() returns a zeroed static buffer if the frame is muted. |
340 // mutable_frame() always returns a non-static buffer; the first call to | 351 // mutable_frame() always returns a non-static buffer; the first call to |
341 // mutable_frame() zeros the non-static buffer and marks the frame unmuted. | 352 // mutable_frame() zeros the non-static buffer and marks the frame unmuted. |
342 const int16_t* data() const; | 353 const int16_t* data() const; |
343 int16_t* mutable_data(); | 354 int16_t* mutable_data(); |
344 | 355 |
345 // Prefer to mute frames using AudioFrameOperations::Mute. | 356 // Prefer to mute frames using AudioFrameOperations::Mute. |
346 void Mute(); | 357 void Mute(); |
347 // Frame is muted by default. | 358 // Frame is muted by default. |
348 bool muted() const; | 359 bool muted() const; |
(...skipping 12 matching lines...) Expand all Loading... | |
361 // -1 represents an uninitialized value. | 372 // -1 represents an uninitialized value. |
362 int64_t elapsed_time_ms_ = -1; | 373 int64_t elapsed_time_ms_ = -1; |
363 // NTP time of the estimated capture time in local timebase in milliseconds. | 374 // NTP time of the estimated capture time in local timebase in milliseconds. |
364 // -1 represents an uninitialized value. | 375 // -1 represents an uninitialized value. |
365 int64_t ntp_time_ms_ = -1; | 376 int64_t ntp_time_ms_ = -1; |
366 size_t samples_per_channel_ = 0; | 377 size_t samples_per_channel_ = 0; |
367 int sample_rate_hz_ = 0; | 378 int sample_rate_hz_ = 0; |
368 size_t num_channels_ = 0; | 379 size_t num_channels_ = 0; |
369 SpeechType speech_type_ = kUndefined; | 380 SpeechType speech_type_ = kUndefined; |
370 VADActivity vad_activity_ = kVadUnknown; | 381 VADActivity vad_activity_ = kVadUnknown; |
382 // Monotonically increasing timestamp intended for profiling of audio frames. | |
383 // Typically used for measuring elapsed time between two different points in | |
384 // the audio path. No lock is used to save resources and we are thread safe | |
385 // by design. Also, rtc::Optional is not used since it will cause a "complex | |
hlundin-webrtc
2017/09/14 13:45:39
+kwiberg@, would you consider this reason enough t
henrika_webrtc
2017/09/15 13:33:57
IMHO, adding a cc-file for this functionality only
kwiberg-webrtc
2017/09/15 17:52:29
If build targets are set up properly (as they shou
| |
386 // class/struct needs an explicit out-of-line destructor" build error. | |
387 int64_t profile_time_stamp_ms_ = 0; | |
hlundin-webrtc
2017/09/14 13:34:33
The convention in this file is to write timestamp
henrika_webrtc
2017/09/15 13:33:57
Done.
| |
371 | 388 |
372 private: | 389 private: |
373 // A permamently zeroed out buffer to represent muted frames. This is a | 390 // A permamently zeroed out buffer to represent muted frames. This is a |
374 // header-only class, so the only way to avoid creating a separate empty | 391 // header-only class, so the only way to avoid creating a separate empty |
375 // buffer per translation unit is to wrap a static in an inline function. | 392 // buffer per translation unit is to wrap a static in an inline function. |
376 static const int16_t* empty_data() { | 393 static const int16_t* empty_data() { |
377 static const int16_t kEmptyData[kMaxDataSizeSamples] = {0}; | 394 static const int16_t kEmptyData[kMaxDataSizeSamples] = {0}; |
378 static_assert(sizeof(kEmptyData) == kMaxDataSizeBytes, "kMaxDataSizeBytes"); | 395 static_assert(sizeof(kEmptyData) == kMaxDataSizeBytes, "kMaxDataSizeBytes"); |
379 return kEmptyData; | 396 return kEmptyData; |
380 } | 397 } |
(...skipping 19 matching lines...) Expand all Loading... | |
400 // TODO(wu): Zero is a valid value for |timestamp_|. We should initialize | 417 // TODO(wu): Zero is a valid value for |timestamp_|. We should initialize |
401 // to an invalid value, or add a new member to indicate invalidity. | 418 // to an invalid value, or add a new member to indicate invalidity. |
402 timestamp_ = 0; | 419 timestamp_ = 0; |
403 elapsed_time_ms_ = -1; | 420 elapsed_time_ms_ = -1; |
404 ntp_time_ms_ = -1; | 421 ntp_time_ms_ = -1; |
405 samples_per_channel_ = 0; | 422 samples_per_channel_ = 0; |
406 sample_rate_hz_ = 0; | 423 sample_rate_hz_ = 0; |
407 num_channels_ = 0; | 424 num_channels_ = 0; |
408 speech_type_ = kUndefined; | 425 speech_type_ = kUndefined; |
409 vad_activity_ = kVadUnknown; | 426 vad_activity_ = kVadUnknown; |
427 profile_time_stamp_ms_ = 0; | |
410 } | 428 } |
411 | 429 |
412 inline void AudioFrame::UpdateFrame(int id, | 430 inline void AudioFrame::UpdateFrame(int id, |
413 uint32_t timestamp, | 431 uint32_t timestamp, |
414 const int16_t* data, | 432 const int16_t* data, |
415 size_t samples_per_channel, | 433 size_t samples_per_channel, |
416 int sample_rate_hz, | 434 int sample_rate_hz, |
417 SpeechType speech_type, | 435 SpeechType speech_type, |
418 VADActivity vad_activity, | 436 VADActivity vad_activity, |
419 size_t num_channels) { | 437 size_t num_channels) { |
(...skipping 30 matching lines...) Expand all Loading... | |
450 num_channels_ = src.num_channels_; | 468 num_channels_ = src.num_channels_; |
451 | 469 |
452 const size_t length = samples_per_channel_ * num_channels_; | 470 const size_t length = samples_per_channel_ * num_channels_; |
453 assert(length <= kMaxDataSizeSamples); | 471 assert(length <= kMaxDataSizeSamples); |
454 if (!src.muted()) { | 472 if (!src.muted()) { |
455 memcpy(data_, src.data(), sizeof(int16_t) * length); | 473 memcpy(data_, src.data(), sizeof(int16_t) * length); |
456 muted_ = false; | 474 muted_ = false; |
457 } | 475 } |
458 } | 476 } |
459 | 477 |
478 inline void AudioFrame::UpdateProfileTime() { | |
479 { | |
hlundin-webrtc
2017/09/14 13:34:33
Why the extra braces?
henrika_webrtc
2017/09/15 13:33:57
My bad
| |
480 profile_time_stamp_ms_ = rtc::TimeMillis() ; | |
hlundin-webrtc
2017/09/14 13:34:33
Delete space before ;
henrika_webrtc
2017/09/15 13:33:57
Done.
| |
481 } | |
482 } | |
483 | |
484 inline int64_t AudioFrame::TimeSinceLastProfile() const { | |
485 if (profile_time_stamp_ms_ == 0) { | |
486 // Profiling has not been activated. | |
487 return -1; | |
488 } | |
489 return rtc::TimeSince(profile_time_stamp_ms_); | |
490 } | |
491 | |
460 inline const int16_t* AudioFrame::data() const { | 492 inline const int16_t* AudioFrame::data() const { |
461 return muted_ ? empty_data() : data_; | 493 return muted_ ? empty_data() : data_; |
462 } | 494 } |
463 | 495 |
464 // TODO(henrik.lundin) Can we skip zeroing the buffer? | 496 // TODO(henrik.lundin) Can we skip zeroing the buffer? |
465 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5647. | 497 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5647. |
466 inline int16_t* AudioFrame::mutable_data() { | 498 inline int16_t* AudioFrame::mutable_data() { |
467 if (muted_) { | 499 if (muted_) { |
468 memset(data_, 0, kMaxDataSizeBytes); | 500 memset(data_, 0, kMaxDataSizeBytes); |
469 muted_ = false; | 501 muted_ = false; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 static constexpr int kNotAProbe = -1; | 670 static constexpr int kNotAProbe = -1; |
639 int send_bitrate_bps = -1; | 671 int send_bitrate_bps = -1; |
640 int probe_cluster_id = kNotAProbe; | 672 int probe_cluster_id = kNotAProbe; |
641 int probe_cluster_min_probes = -1; | 673 int probe_cluster_min_probes = -1; |
642 int probe_cluster_min_bytes = -1; | 674 int probe_cluster_min_bytes = -1; |
643 }; | 675 }; |
644 | 676 |
645 } // namespace webrtc | 677 } // namespace webrtc |
646 | 678 |
647 #endif // WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 679 #endif // WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
OLD | NEW |