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 #include <assert.h> | 11 #include <assert.h> |
12 | 12 |
13 #include "webrtc/base/format_macros.h" | 13 #include "webrtc/base/format_macros.h" |
14 #include "webrtc/modules/media_file/media_file_impl.h" | 14 #include "webrtc/modules/media_file/media_file_impl.h" |
15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
16 #include "webrtc/system_wrappers/include/file_wrapper.h" | 15 #include "webrtc/system_wrappers/include/file_wrapper.h" |
17 #include "webrtc/system_wrappers/include/trace.h" | 16 #include "webrtc/system_wrappers/include/trace.h" |
18 | 17 |
19 namespace webrtc { | 18 namespace webrtc { |
20 MediaFile* MediaFile::CreateMediaFile(const int32_t id) | 19 MediaFile* MediaFile::CreateMediaFile(const int32_t id) |
21 { | 20 { |
22 return new MediaFileImpl(id); | 21 return new MediaFileImpl(id); |
23 } | 22 } |
24 | 23 |
25 void MediaFile::DestroyMediaFile(MediaFile* module) | 24 void MediaFile::DestroyMediaFile(MediaFile* module) |
26 { | 25 { |
27 delete static_cast<MediaFileImpl*>(module); | 26 delete static_cast<MediaFileImpl*>(module); |
28 } | 27 } |
29 | 28 |
30 MediaFileImpl::MediaFileImpl(const int32_t id) | 29 MediaFileImpl::MediaFileImpl(const int32_t id) |
31 : _id(id), | 30 : _id(id), |
32 _crit(CriticalSectionWrapper::CreateCriticalSection()), | |
33 _callbackCrit(CriticalSectionWrapper::CreateCriticalSection()), | |
34 _ptrFileUtilityObj(NULL), | 31 _ptrFileUtilityObj(NULL), |
35 codec_info_(), | 32 codec_info_(), |
36 _ptrInStream(NULL), | 33 _ptrInStream(NULL), |
37 _ptrOutStream(NULL), | 34 _ptrOutStream(NULL), |
38 _fileFormat((FileFormats)-1), | 35 _fileFormat((FileFormats)-1), |
39 _recordDurationMs(0), | 36 _recordDurationMs(0), |
40 _playoutPositionMs(0), | 37 _playoutPositionMs(0), |
41 _notificationMs(0), | 38 _notificationMs(0), |
42 _playingActive(false), | 39 _playingActive(false), |
43 _recordingActive(false), | 40 _recordingActive(false), |
44 _isStereo(false), | 41 _isStereo(false), |
45 _openFile(false), | 42 _openFile(false), |
46 _fileName(), | 43 _fileName(), |
47 _ptrCallback(NULL) | 44 _ptrCallback(NULL) |
48 { | 45 { |
49 WEBRTC_TRACE(kTraceMemory, kTraceFile, id, "Created"); | 46 WEBRTC_TRACE(kTraceMemory, kTraceFile, id, "Created"); |
50 | 47 |
51 codec_info_.plname[0] = '\0'; | 48 codec_info_.plname[0] = '\0'; |
52 _fileName[0] = '\0'; | 49 _fileName[0] = '\0'; |
53 } | 50 } |
54 | 51 |
55 | 52 |
56 MediaFileImpl::~MediaFileImpl() | 53 MediaFileImpl::~MediaFileImpl() |
57 { | 54 { |
58 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, "~MediaFileImpl()"); | 55 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, "~MediaFileImpl()"); |
59 { | 56 { |
60 CriticalSectionScoped lock(_crit); | 57 rtc::CritScope lock(&_crit); |
61 | 58 |
62 if(_playingActive) | 59 if(_playingActive) |
63 { | 60 { |
64 StopPlaying(); | 61 StopPlaying(); |
65 } | 62 } |
66 | 63 |
67 if(_recordingActive) | 64 if(_recordingActive) |
68 { | 65 { |
69 StopRecording(); | 66 StopRecording(); |
70 } | 67 } |
71 | 68 |
72 delete _ptrFileUtilityObj; | 69 delete _ptrFileUtilityObj; |
73 | 70 |
74 if(_openFile) | 71 if(_openFile) |
75 { | 72 { |
76 delete _ptrInStream; | 73 delete _ptrInStream; |
77 _ptrInStream = NULL; | 74 _ptrInStream = NULL; |
78 delete _ptrOutStream; | 75 delete _ptrOutStream; |
79 _ptrOutStream = NULL; | 76 _ptrOutStream = NULL; |
80 } | 77 } |
81 } | 78 } |
82 | |
83 delete _crit; | |
84 delete _callbackCrit; | |
85 } | 79 } |
86 | 80 |
87 int64_t MediaFileImpl::TimeUntilNextProcess() | 81 int64_t MediaFileImpl::TimeUntilNextProcess() |
88 { | 82 { |
89 WEBRTC_TRACE( | 83 WEBRTC_TRACE( |
90 kTraceWarning, | 84 kTraceWarning, |
91 kTraceFile, | 85 kTraceFile, |
92 _id, | 86 _id, |
93 "TimeUntilNextProcess: This method is not used by MediaFile class."); | 87 "TimeUntilNextProcess: This method is not used by MediaFile class."); |
94 return -1; | 88 return -1; |
(...skipping 17 matching lines...) Expand all Loading... |
112 | 106 |
113 if(buffer == NULL || bufferLengthInBytes == 0) | 107 if(buffer == NULL || bufferLengthInBytes == 0) |
114 { | 108 { |
115 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 109 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
116 "Buffer pointer or length is NULL!"); | 110 "Buffer pointer or length is NULL!"); |
117 return -1; | 111 return -1; |
118 } | 112 } |
119 | 113 |
120 int32_t bytesRead = 0; | 114 int32_t bytesRead = 0; |
121 { | 115 { |
122 CriticalSectionScoped lock(_crit); | 116 rtc::CritScope lock(&_crit); |
123 | 117 |
124 if(!_playingActive) | 118 if(!_playingActive) |
125 { | 119 { |
126 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, | 120 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, |
127 "Not currently playing!"); | 121 "Not currently playing!"); |
128 return -1; | 122 return -1; |
129 } | 123 } |
130 | 124 |
131 if(!_ptrFileUtilityObj) | 125 if(!_ptrFileUtilityObj) |
132 { | 126 { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 200 } |
207 } | 201 } |
208 else | 202 else |
209 { | 203 { |
210 // If no bytes were read assume end of file. | 204 // If no bytes were read assume end of file. |
211 StopPlaying(); | 205 StopPlaying(); |
212 playEnded = true; | 206 playEnded = true; |
213 } | 207 } |
214 | 208 |
215 // Only _callbackCrit may and should be taken when making callbacks. | 209 // Only _callbackCrit may and should be taken when making callbacks. |
216 CriticalSectionScoped lock(_callbackCrit); | 210 rtc::CritScope lock(&_callbackCrit); |
217 if(_ptrCallback) | 211 if(_ptrCallback) |
218 { | 212 { |
219 if(callbackNotifyMs) | 213 if(callbackNotifyMs) |
220 { | 214 { |
221 _ptrCallback->PlayNotification(_id, callbackNotifyMs); | 215 _ptrCallback->PlayNotification(_id, callbackNotifyMs); |
222 } | 216 } |
223 if(playEnded) | 217 if(playEnded) |
224 { | 218 { |
225 _ptrCallback->PlayFileEnded(_id); | 219 _ptrCallback->PlayFileEnded(_id); |
226 } | 220 } |
(...skipping 18 matching lines...) Expand all Loading... |
245 if(bufferLeft == NULL || bufferRight == NULL || bufferLengthInBytes == 0) | 239 if(bufferLeft == NULL || bufferRight == NULL || bufferLengthInBytes == 0) |
246 { | 240 { |
247 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 241 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
248 "A buffer pointer or the length is NULL!"); | 242 "A buffer pointer or the length is NULL!"); |
249 return -1; | 243 return -1; |
250 } | 244 } |
251 | 245 |
252 bool playEnded = false; | 246 bool playEnded = false; |
253 uint32_t callbackNotifyMs = 0; | 247 uint32_t callbackNotifyMs = 0; |
254 { | 248 { |
255 CriticalSectionScoped lock(_crit); | 249 rtc::CritScope lock(&_crit); |
256 | 250 |
257 if(!_playingActive || !_isStereo) | 251 if(!_playingActive || !_isStereo) |
258 { | 252 { |
259 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, | 253 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, |
260 "Not currently playing stereo!"); | 254 "Not currently playing stereo!"); |
261 return -1; | 255 return -1; |
262 } | 256 } |
263 | 257 |
264 if(!_ptrFileUtilityObj) | 258 if(!_ptrFileUtilityObj) |
265 { | 259 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 300 } |
307 } | 301 } |
308 else | 302 else |
309 { | 303 { |
310 // If no bytes were read assume end of file. | 304 // If no bytes were read assume end of file. |
311 StopPlaying(); | 305 StopPlaying(); |
312 playEnded = true; | 306 playEnded = true; |
313 } | 307 } |
314 } | 308 } |
315 | 309 |
316 CriticalSectionScoped lock(_callbackCrit); | 310 rtc::CritScope lock(&_callbackCrit); |
317 if(_ptrCallback) | 311 if(_ptrCallback) |
318 { | 312 { |
319 if(callbackNotifyMs) | 313 if(callbackNotifyMs) |
320 { | 314 { |
321 _ptrCallback->PlayNotification(_id, callbackNotifyMs); | 315 _ptrCallback->PlayNotification(_id, callbackNotifyMs); |
322 } | 316 } |
323 if(playEnded) | 317 if(playEnded) |
324 { | 318 { |
325 _ptrCallback->PlayFileEnded(_id); | 319 _ptrCallback->PlayFileEnded(_id); |
326 } | 320 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 373 } |
380 | 374 |
381 if(StartPlayingStream(*inputStream, loop, notificationTimeMs, | 375 if(StartPlayingStream(*inputStream, loop, notificationTimeMs, |
382 format, codecInst, startPointMs, stopPointMs) == -1) | 376 format, codecInst, startPointMs, stopPointMs) == -1) |
383 { | 377 { |
384 inputStream->CloseFile(); | 378 inputStream->CloseFile(); |
385 delete inputStream; | 379 delete inputStream; |
386 return -1; | 380 return -1; |
387 } | 381 } |
388 | 382 |
389 CriticalSectionScoped lock(_crit); | 383 rtc::CritScope lock(&_crit); |
390 _openFile = true; | 384 _openFile = true; |
391 strncpy(_fileName, fileName, sizeof(_fileName)); | 385 strncpy(_fileName, fileName, sizeof(_fileName)); |
392 _fileName[sizeof(_fileName) - 1] = '\0'; | 386 _fileName[sizeof(_fileName) - 1] = '\0'; |
393 return 0; | 387 return 0; |
394 } | 388 } |
395 | 389 |
396 int32_t MediaFileImpl::StartPlayingAudioStream( | 390 int32_t MediaFileImpl::StartPlayingAudioStream( |
397 InStream& stream, | 391 InStream& stream, |
398 const uint32_t notificationTimeMs, | 392 const uint32_t notificationTimeMs, |
399 const FileFormats format, | 393 const FileFormats format, |
(...skipping 17 matching lines...) Expand all Loading... |
417 if(!ValidFileFormat(format,codecInst)) | 411 if(!ValidFileFormat(format,codecInst)) |
418 { | 412 { |
419 return -1; | 413 return -1; |
420 } | 414 } |
421 | 415 |
422 if(!ValidFilePositions(startPointMs,stopPointMs)) | 416 if(!ValidFilePositions(startPointMs,stopPointMs)) |
423 { | 417 { |
424 return -1; | 418 return -1; |
425 } | 419 } |
426 | 420 |
427 CriticalSectionScoped lock(_crit); | 421 rtc::CritScope lock(&_crit); |
428 if(_playingActive || _recordingActive) | 422 if(_playingActive || _recordingActive) |
429 { | 423 { |
430 WEBRTC_TRACE( | 424 WEBRTC_TRACE( |
431 kTraceError, | 425 kTraceError, |
432 kTraceFile, | 426 kTraceFile, |
433 _id, | 427 _id, |
434 "StartPlaying called, but already playing or recording file %s", | 428 "StartPlaying called, but already playing or recording file %s", |
435 (_fileName[0] == '\0') ? "(name not set)" : _fileName); | 429 (_fileName[0] == '\0') ? "(name not set)" : _fileName); |
436 return -1; | 430 return -1; |
437 } | 431 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 _playoutPositionMs = _ptrFileUtilityObj->PlayoutPositionMs(); | 542 _playoutPositionMs = _ptrFileUtilityObj->PlayoutPositionMs(); |
549 _ptrInStream = &stream; | 543 _ptrInStream = &stream; |
550 _notificationMs = notificationTimeMs; | 544 _notificationMs = notificationTimeMs; |
551 | 545 |
552 return 0; | 546 return 0; |
553 } | 547 } |
554 | 548 |
555 int32_t MediaFileImpl::StopPlaying() | 549 int32_t MediaFileImpl::StopPlaying() |
556 { | 550 { |
557 | 551 |
558 CriticalSectionScoped lock(_crit); | 552 rtc::CritScope lock(&_crit); |
559 _isStereo = false; | 553 _isStereo = false; |
560 if(_ptrFileUtilityObj) | 554 if(_ptrFileUtilityObj) |
561 { | 555 { |
562 delete _ptrFileUtilityObj; | 556 delete _ptrFileUtilityObj; |
563 _ptrFileUtilityObj = NULL; | 557 _ptrFileUtilityObj = NULL; |
564 } | 558 } |
565 if(_ptrInStream) | 559 if(_ptrInStream) |
566 { | 560 { |
567 // If MediaFileImpl opened the InStream it must be reclaimed here. | 561 // If MediaFileImpl opened the InStream it must be reclaimed here. |
568 if(_openFile) | 562 if(_openFile) |
(...skipping 14 matching lines...) Expand all Loading... |
583 return -1; | 577 return -1; |
584 } | 578 } |
585 | 579 |
586 _playingActive = false; | 580 _playingActive = false; |
587 return 0; | 581 return 0; |
588 } | 582 } |
589 | 583 |
590 bool MediaFileImpl::IsPlaying() | 584 bool MediaFileImpl::IsPlaying() |
591 { | 585 { |
592 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsPlaying()"); | 586 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsPlaying()"); |
593 CriticalSectionScoped lock(_crit); | 587 rtc::CritScope lock(&_crit); |
594 return _playingActive; | 588 return _playingActive; |
595 } | 589 } |
596 | 590 |
597 int32_t MediaFileImpl::IncomingAudioData( | 591 int32_t MediaFileImpl::IncomingAudioData( |
598 const int8_t* buffer, | 592 const int8_t* buffer, |
599 const size_t bufferLengthInBytes) | 593 const size_t bufferLengthInBytes) |
600 { | 594 { |
601 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 595 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
602 "MediaFile::IncomingData(buffer= 0x%x, bufLen= %" PRIuS, | 596 "MediaFile::IncomingData(buffer= 0x%x, bufLen= %" PRIuS, |
603 buffer, bufferLengthInBytes); | 597 buffer, bufferLengthInBytes); |
604 | 598 |
605 if(buffer == NULL || bufferLengthInBytes == 0) | 599 if(buffer == NULL || bufferLengthInBytes == 0) |
606 { | 600 { |
607 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 601 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
608 "Buffer pointer or length is NULL!"); | 602 "Buffer pointer or length is NULL!"); |
609 return -1; | 603 return -1; |
610 } | 604 } |
611 | 605 |
612 bool recordingEnded = false; | 606 bool recordingEnded = false; |
613 uint32_t callbackNotifyMs = 0; | 607 uint32_t callbackNotifyMs = 0; |
614 { | 608 { |
615 CriticalSectionScoped lock(_crit); | 609 rtc::CritScope lock(&_crit); |
616 | 610 |
617 if(!_recordingActive) | 611 if(!_recordingActive) |
618 { | 612 { |
619 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, | 613 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, |
620 "Not currently recording!"); | 614 "Not currently recording!"); |
621 return -1; | 615 return -1; |
622 } | 616 } |
623 if(_ptrOutStream == NULL) | 617 if(_ptrOutStream == NULL) |
624 { | 618 { |
625 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 619 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 if(bytesWritten < (int32_t)bufferLengthInBytes) | 694 if(bytesWritten < (int32_t)bufferLengthInBytes) |
701 { | 695 { |
702 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, | 696 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, |
703 "Failed to write all requested bytes!"); | 697 "Failed to write all requested bytes!"); |
704 StopRecording(); | 698 StopRecording(); |
705 recordingEnded = true; | 699 recordingEnded = true; |
706 } | 700 } |
707 } | 701 } |
708 | 702 |
709 // Only _callbackCrit may and should be taken when making callbacks. | 703 // Only _callbackCrit may and should be taken when making callbacks. |
710 CriticalSectionScoped lock(_callbackCrit); | 704 rtc::CritScope lock(&_callbackCrit); |
711 if(_ptrCallback) | 705 if(_ptrCallback) |
712 { | 706 { |
713 if(callbackNotifyMs) | 707 if(callbackNotifyMs) |
714 { | 708 { |
715 _ptrCallback->RecordNotification(_id, callbackNotifyMs); | 709 _ptrCallback->RecordNotification(_id, callbackNotifyMs); |
716 } | 710 } |
717 if(recordingEnded) | 711 if(recordingEnded) |
718 { | 712 { |
719 _ptrCallback->RecordFileEnded(_id); | 713 _ptrCallback->RecordFileEnded(_id); |
720 return -1; | 714 return -1; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 } | 754 } |
761 | 755 |
762 if(StartRecordingAudioStream(*outputStream, format, codecInst, | 756 if(StartRecordingAudioStream(*outputStream, format, codecInst, |
763 notificationTimeMs) == -1) | 757 notificationTimeMs) == -1) |
764 { | 758 { |
765 outputStream->CloseFile(); | 759 outputStream->CloseFile(); |
766 delete outputStream; | 760 delete outputStream; |
767 return -1; | 761 return -1; |
768 } | 762 } |
769 | 763 |
770 CriticalSectionScoped lock(_crit); | 764 rtc::CritScope lock(&_crit); |
771 _openFile = true; | 765 _openFile = true; |
772 strncpy(_fileName, fileName, sizeof(_fileName)); | 766 strncpy(_fileName, fileName, sizeof(_fileName)); |
773 _fileName[sizeof(_fileName) - 1] = '\0'; | 767 _fileName[sizeof(_fileName) - 1] = '\0'; |
774 return 0; | 768 return 0; |
775 } | 769 } |
776 | 770 |
777 int32_t MediaFileImpl::StartRecordingAudioStream( | 771 int32_t MediaFileImpl::StartRecordingAudioStream( |
778 OutStream& stream, | 772 OutStream& stream, |
779 const FileFormats format, | 773 const FileFormats format, |
780 const CodecInst& codecInst, | 774 const CodecInst& codecInst, |
781 const uint32_t notificationTimeMs) | 775 const uint32_t notificationTimeMs) |
782 { | 776 { |
783 // Check codec info | 777 // Check codec info |
784 if(!ValidFileFormat(format,&codecInst)) | 778 if(!ValidFileFormat(format,&codecInst)) |
785 { | 779 { |
786 return -1; | 780 return -1; |
787 } | 781 } |
788 | 782 |
789 CriticalSectionScoped lock(_crit); | 783 rtc::CritScope lock(&_crit); |
790 if(_recordingActive || _playingActive) | 784 if(_recordingActive || _playingActive) |
791 { | 785 { |
792 WEBRTC_TRACE( | 786 WEBRTC_TRACE( |
793 kTraceError, | 787 kTraceError, |
794 kTraceFile, | 788 kTraceFile, |
795 _id, | 789 _id, |
796 "StartRecording called, but already recording or playing file %s!", | 790 "StartRecording called, but already recording or playing file %s!", |
797 _fileName); | 791 _fileName); |
798 return -1; | 792 return -1; |
799 } | 793 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 _recordingActive = true; | 910 _recordingActive = true; |
917 _ptrOutStream = &stream; | 911 _ptrOutStream = &stream; |
918 _notificationMs = notificationTimeMs; | 912 _notificationMs = notificationTimeMs; |
919 _recordDurationMs = 0; | 913 _recordDurationMs = 0; |
920 return 0; | 914 return 0; |
921 } | 915 } |
922 | 916 |
923 int32_t MediaFileImpl::StopRecording() | 917 int32_t MediaFileImpl::StopRecording() |
924 { | 918 { |
925 | 919 |
926 CriticalSectionScoped lock(_crit); | 920 rtc::CritScope lock(&_crit); |
927 if(!_recordingActive) | 921 if(!_recordingActive) |
928 { | 922 { |
929 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, | 923 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, |
930 "recording is not active!"); | 924 "recording is not active!"); |
931 return -1; | 925 return -1; |
932 } | 926 } |
933 | 927 |
934 _isStereo = false; | 928 _isStereo = false; |
935 | 929 |
936 if(_ptrFileUtilityObj != NULL) | 930 if(_ptrFileUtilityObj != NULL) |
(...skipping 23 matching lines...) Expand all Loading... |
960 _recordingActive = false; | 954 _recordingActive = false; |
961 codec_info_.pltype = 0; | 955 codec_info_.pltype = 0; |
962 codec_info_.plname[0] = '\0'; | 956 codec_info_.plname[0] = '\0'; |
963 | 957 |
964 return 0; | 958 return 0; |
965 } | 959 } |
966 | 960 |
967 bool MediaFileImpl::IsRecording() | 961 bool MediaFileImpl::IsRecording() |
968 { | 962 { |
969 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsRecording()"); | 963 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsRecording()"); |
970 CriticalSectionScoped lock(_crit); | 964 rtc::CritScope lock(&_crit); |
971 return _recordingActive; | 965 return _recordingActive; |
972 } | 966 } |
973 | 967 |
974 int32_t MediaFileImpl::RecordDurationMs(uint32_t& durationMs) | 968 int32_t MediaFileImpl::RecordDurationMs(uint32_t& durationMs) |
975 { | 969 { |
976 | 970 |
977 CriticalSectionScoped lock(_crit); | 971 rtc::CritScope lock(&_crit); |
978 if(!_recordingActive) | 972 if(!_recordingActive) |
979 { | 973 { |
980 durationMs = 0; | 974 durationMs = 0; |
981 return -1; | 975 return -1; |
982 } | 976 } |
983 durationMs = _recordDurationMs; | 977 durationMs = _recordDurationMs; |
984 return 0; | 978 return 0; |
985 } | 979 } |
986 | 980 |
987 bool MediaFileImpl::IsStereo() | 981 bool MediaFileImpl::IsStereo() |
988 { | 982 { |
989 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsStereo()"); | 983 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsStereo()"); |
990 CriticalSectionScoped lock(_crit); | 984 rtc::CritScope lock(&_crit); |
991 return _isStereo; | 985 return _isStereo; |
992 } | 986 } |
993 | 987 |
994 int32_t MediaFileImpl::SetModuleFileCallback(FileCallback* callback) | 988 int32_t MediaFileImpl::SetModuleFileCallback(FileCallback* callback) |
995 { | 989 { |
996 | 990 |
997 CriticalSectionScoped lock(_callbackCrit); | 991 rtc::CritScope lock(&_callbackCrit); |
998 | 992 |
999 _ptrCallback = callback; | 993 _ptrCallback = callback; |
1000 return 0; | 994 return 0; |
1001 } | 995 } |
1002 | 996 |
1003 int32_t MediaFileImpl::FileDurationMs(const char* fileName, | 997 int32_t MediaFileImpl::FileDurationMs(const char* fileName, |
1004 uint32_t& durationMs, | 998 uint32_t& durationMs, |
1005 const FileFormats format, | 999 const FileFormats format, |
1006 const uint32_t freqInHz) | 1000 const uint32_t freqInHz) |
1007 { | 1001 { |
(...skipping 23 matching lines...) Expand all Loading... |
1031 durationMs = 0; | 1025 durationMs = 0; |
1032 return -1; | 1026 return -1; |
1033 } | 1027 } |
1034 | 1028 |
1035 durationMs = duration; | 1029 durationMs = duration; |
1036 return 0; | 1030 return 0; |
1037 } | 1031 } |
1038 | 1032 |
1039 int32_t MediaFileImpl::PlayoutPositionMs(uint32_t& positionMs) const | 1033 int32_t MediaFileImpl::PlayoutPositionMs(uint32_t& positionMs) const |
1040 { | 1034 { |
1041 CriticalSectionScoped lock(_crit); | 1035 rtc::CritScope lock(&_crit); |
1042 if(!_playingActive) | 1036 if(!_playingActive) |
1043 { | 1037 { |
1044 positionMs = 0; | 1038 positionMs = 0; |
1045 return -1; | 1039 return -1; |
1046 } | 1040 } |
1047 positionMs = _playoutPositionMs; | 1041 positionMs = _playoutPositionMs; |
1048 return 0; | 1042 return 0; |
1049 } | 1043 } |
1050 | 1044 |
1051 int32_t MediaFileImpl::codec_info(CodecInst& codecInst) const | 1045 int32_t MediaFileImpl::codec_info(CodecInst& codecInst) const |
1052 { | 1046 { |
1053 CriticalSectionScoped lock(_crit); | 1047 rtc::CritScope lock(&_crit); |
1054 if(!_playingActive && !_recordingActive) | 1048 if(!_playingActive && !_recordingActive) |
1055 { | 1049 { |
1056 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1050 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
1057 "Neither playout nor recording has been initialized!"); | 1051 "Neither playout nor recording has been initialized!"); |
1058 return -1; | 1052 return -1; |
1059 } | 1053 } |
1060 if (codec_info_.pltype == 0 && codec_info_.plname[0] == '\0') | 1054 if (codec_info_.pltype == 0 && codec_info_.plname[0] == '\0') |
1061 { | 1055 { |
1062 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1056 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
1063 "The CodecInst for %s is unknown!", | 1057 "The CodecInst for %s is unknown!", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 { | 1117 { |
1124 if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000)) | 1118 if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000)) |
1125 { | 1119 { |
1126 return true; | 1120 return true; |
1127 } | 1121 } |
1128 WEBRTC_TRACE(kTraceError, kTraceFile, -1, | 1122 WEBRTC_TRACE(kTraceError, kTraceFile, -1, |
1129 "Frequency should be 8000, 16000 or 32000 (Hz)"); | 1123 "Frequency should be 8000, 16000 or 32000 (Hz)"); |
1130 return false; | 1124 return false; |
1131 } | 1125 } |
1132 } // namespace webrtc | 1126 } // namespace webrtc |
OLD | NEW |