Ticket #8911: 0001-BMediaRecorder-fix-a-few-issues-fix-style-remove-unu.patch
File 0001-BMediaRecorder-fix-a-few-issues-fix-style-remove-unu.patch, 25.6 KB (added by , 9 years ago) |
---|
-
headers/private/media/MediaRecorder.h
From 9cb79b4d2047e2e4eab3aed0976ec2942ea426dc Mon Sep 17 00:00:00 2001 From: Hamish Morrison <hamishm53@gmail.com> Date: Tue, 10 Jun 2014 21:23:34 +0100 Subject: [PATCH] BMediaRecorder: fix a few issues, fix style, remove unused SoundUtils * Use the preferred time source (GetTimeSource) for the node * Fix node releasing when creating the connection fails * Add virtual slots and padding * Refactor _Connect method --- headers/private/media/MediaRecorder.h | 87 +++++++----- headers/private/media/MediaRecorderNode.h | 22 ++- headers/private/media/SoundUtils.h | 56 -------- src/apps/soundrecorder/RecorderWindow.cpp | 8 +- src/apps/soundrecorder/RecorderWindow.h | 2 +- src/kits/media/Jamfile | 3 +- src/kits/media/MediaRecorder.cpp | 227 +++++++++++++----------------- src/kits/media/MediaRecorderNode.cpp | 14 +- src/kits/media/SoundUtils.cpp | 107 -------------- 9 files changed, 164 insertions(+), 362 deletions(-) delete mode 100644 headers/private/media/SoundUtils.h delete mode 100644 src/kits/media/SoundUtils.cpp diff --git a/headers/private/media/MediaRecorder.h b/headers/private/media/MediaRecorder.h index 8b6d54e..417be03 100644
a b 6 6 #define _MEDIA_RECORDER_H 7 7 8 8 9 #include <MediaDefs.h> 9 10 #include <MediaNode.h> 10 #include <TimeSource.h>11 12 #include "MediaRecorderNode.h"13 #include "SoundUtils.h"14 11 15 12 16 13 namespace BPrivate { namespace media { 17 14 15 16 class BMediaRecorderNode; 17 18 18 class BMediaRecorder { 19 19 public: 20 enum notification { 21 B_WILL_START = 1, // performance_time 22 B_WILL_STOP, // performance_time immediate 23 B_WILL_SEEK, // performance_time media_time 24 B_WILL_TIMEWARP, // real_time performance_time 25 }; 26 27 typedef void (*ProcessFunc)(void* cookie, 28 bigtime_t timestamp, void* data, 29 size_t size, const media_format& format); 30 31 typedef void (*NotifyFunc)(void* cookie, 32 notification what, ...); 33 34 public: 20 35 BMediaRecorder(const char* name, 21 36 media_type type 22 37 = B_MEDIA_UNKNOWN_TYPE); … … public: 25 40 26 41 status_t InitCheck() const; 27 42 28 typedef void (*ProcessFunc)(void* cookie,29 bigtime_t timestamp, void* data,30 size_t datasize,31 const media_format& format);32 33 typedef void (*NotifyFunc)(void* cookie,34 int32 code, ...);35 36 43 status_t SetHooks(ProcessFunc recordFunc = NULL, 37 44 NotifyFunc notifyFunc = NULL, 38 45 void* cookie = NULL); … … public: 43 50 virtual status_t Start(bool force = false); 44 51 virtual status_t Stop(bool force = false); 45 52 46 virtual status_t Connect(const media_format& format, 47 uint32 flags = 0); 53 virtual status_t Connect(const media_format& format); 48 54 49 55 virtual status_t Connect(const dormant_node_info& dormantInfo, 50 const media_format* format = NULL, 51 uint32 flags = 0); 56 const media_format& format); 52 57 53 58 virtual status_t Connect(const media_node& node, 54 const media_output* useOutput = NULL, 55 const media_format* format = NULL, 56 uint32 flags = 0); 59 const media_output* output = NULL, 60 const media_format* format = NULL); 57 61 58 62 virtual status_t Disconnect(); 59 63 … … public: 67 71 68 72 protected: 69 73 70 virtual void BufferReceived(void* buffer, 71 size_t size, 74 virtual void BufferReceived(void* buffer, size_t size, 72 75 const media_header& header); 73 76 private: 74 77 75 status_t _Connect( 76 const media_format* format, 77 uint32 flags, 78 const dormant_node_info* dormantNode, 79 const media_node* mediaNode, 80 const media_output* output); 78 status_t _Connect(const media_node& mediaNode, 79 const media_output* output, 80 const media_format& format); 81 81 82 status_t fInitErr; 82 virtual void _ReservedMediaRecorder0(); 83 virtual void _ReservedMediaRecorder1(); 84 virtual void _ReservedMediaRecorder2(); 85 virtual void _ReservedMediaRecorder3(); 86 virtual void _ReservedMediaRecorder4(); 87 virtual void _ReservedMediaRecorder5(); 88 virtual void _ReservedMediaRecorder6(); 89 virtual void _ReservedMediaRecorder7(); 83 90 84 bool fConnected; 85 bool fRunning; 91 status_t fInitErr; 86 92 87 BTimeSource* fTimeSource; 93 bool fConnected; 94 bool fRunning; 95 bool fReleaseOutputNode; 88 96 89 ProcessFuncfRecordHook;90 NotifyFuncfNotifyHook;97 ProcessFunc fRecordHook; 98 NotifyFunc fNotifyHook; 91 99 92 media_nodefOutputNode;93 media_outputfOutput;100 media_node fOutputNode; 101 media_output fOutput; 94 102 95 BMediaRecorderNode*fNode;96 media_inputfInput;103 BMediaRecorderNode* fNode; 104 media_input fInput; 97 105 98 void* fBufferCookie; 106 void* fBufferCookie; 107 uint32 fPadding[32]; 99 108 100 friend classBMediaRecorderNode;109 friend class BMediaRecorderNode; 101 110 }; 102 111 103 112 } -
headers/private/media/MediaRecorderNode.h
diff --git a/headers/private/media/MediaRecorderNode.h b/headers/private/media/MediaRecorderNode.h index b1e421e..8a4f2fe 100644
a b 1 1 /* 2 * Copyright 1999, Be Incorporated3 2 * Copyright 2014, Dario Casalinuovo 3 * Copyright 1999, Be Incorporated 4 4 * All Rights Reserved. 5 5 * This file may be used under the terms of the Be Sample Code License. 6 6 */ … … protected: 76 76 virtual void BufferReceived(BBuffer* buffer); 77 77 78 78 virtual void ProducerDataStatus( 79 const media_destination& forWhom,79 const media_destination& destination, 80 80 int32 status, 81 81 bigtime_t performanceTime); 82 82 83 virtual status_t GetLatencyFor( 84 const media_destination& forWhom, 85 bigtime_t* outLatency, 86 media_node_id* outTimesource); 83 virtual status_t GetLatencyFor(const media_destination& destination, 84 bigtime_t* outLatency, 85 media_node_id* outTimesource); 87 86 88 virtual status_t Connected( 89 const media_source& producer, 87 virtual status_t Connected(const media_source& producer, 90 88 const media_destination& where, 91 const media_format& withFormat,89 const media_format& format, 92 90 media_input* outInput); 93 91 94 virtual void Disconnected( 95 const media_source& producer, 92 virtual void Disconnected(const media_source& producer, 96 93 const media_destination& where); 97 94 98 virtual status_t FormatChanged( 99 const media_source& producer, 95 virtual status_t FormatChanged(const media_source& producer, 100 96 const media_destination& consumer, 101 97 int32 tag, 102 98 const media_format& format); -
deleted file headers/private/media/SoundUtils.h
diff --git a/headers/private/media/SoundUtils.h b/headers/private/media/SoundUtils.h deleted file mode 100644 index c9e5ec8..0000000
+ - 1 /*******************************************************************************2 /3 / File: SoundUtils.h4 /5 / Description: Utility functions for handling audio data.6 /7 / Copyright 1998-1999, Be Incorporated, All Rights Reserved8 /9 *******************************************************************************/10 11 #if ! defined( _SoundUtils_h )12 #define _SoundUtils_h13 14 #include <MediaDefs.h>15 16 // Simple helper functions that come in handy when doing17 // buffer calculations.18 double us_to_s(bigtime_t usecs);19 bigtime_t s_to_us(double secs);20 21 int bytes_per_frame(const media_raw_audio_format & format);22 int frames_per_buffer(const media_raw_audio_format & format);23 bigtime_t buffer_duration(const media_raw_audio_format & format);24 bigtime_t frames_duration(const media_raw_audio_format & format,25 int64 num_frames);26 int64 frames_for_duration(const media_raw_audio_format & format,27 bigtime_t duration);28 int buffers_for_duration(const media_raw_audio_format & format,29 bigtime_t duration);30 31 // This is a common hook function interface for32 // SoundConsumer and SoundProducer to use.33 typedef void (*SoundProcessFunc)(void * cookie,34 bigtime_t timestamp, void * data, size_t datasize,35 const media_raw_audio_format & format);36 typedef void (*SoundNotifyFunc)(void * cookie,37 int32 code, ...);38 39 // These are special codes that we use in the Notify40 // function hook.41 enum {42 B_WILL_START = 1, // performance_time43 B_WILL_STOP, // performance_time immediate44 B_WILL_SEEK, // performance_time media_time45 B_WILL_TIMEWARP, // real_time performance_time46 B_CONNECTED, // name (char*)47 B_DISCONNECTED, //48 B_FORMAT_CHANGED, // media_raw_audio_format*49 B_NODE_DIES, // node will die!50 B_HOOKS_CHANGED, //51 B_OP_TIMED_OUT, // timeout that expired -- Consumer only52 B_PRODUCER_DATA_STATUS, // status performance_time -- Consumer only53 B_LATE_NOTICE // how_much performance_time -- Producer only54 };55 56 #endif /* _SoundUtils_h */ -
src/apps/soundrecorder/RecorderWindow.cpp
diff --git a/src/apps/soundrecorder/RecorderWindow.cpp b/src/apps/soundrecorder/RecorderWindow.cpp index a4dbf8a..3868b75 100644
a b 1 1 /* 2 * Copyright 2005, Jérôme Duval. All rights reserved.3 2 * Copyright 2014, Dario Casalinuovo. All rights reserved. 3 * Copyright 2005, Jérôme Duval. All rights reserved. 4 4 * Distributed under the terms of the MIT License. 5 5 * 6 6 * Inspired by SoundCapture from Be newsletter (Media Kit Basics: … … 43 43 #include <TimeSource.h> 44 44 #include <NodeInfo.h> 45 45 46 #include "SoundUtils.h"47 46 #include "RecorderWindow.h" 48 47 #include "FileUtils.h" 49 48 … … RecorderWindow::RecordFile(void* cookie, bigtime_t timestamp, 1224 1223 1225 1224 1226 1225 void 1227 RecorderWindow::NotifyRecordFile(void * cookie, int32 code, ...) 1226 RecorderWindow::NotifyRecordFile(void * cookie, 1227 BMediaRecorder::notification code, ...) 1228 1228 { 1229 if ( (code == B_WILL_STOP) || (code == B_NODE_DIES)) {1229 if (code == BMediaRecorder::B_WILL_STOP) { 1230 1230 RecorderWindow * window = (RecorderWindow *)cookie; 1231 1231 // Tell the window we've stopped, if it doesn't 1232 1232 // already know. -
src/apps/soundrecorder/RecorderWindow.h
diff --git a/src/apps/soundrecorder/RecorderWindow.h b/src/apps/soundrecorder/RecorderWindow.h index d3e3087..d0c405e 100644
a b private: 168 168 void ErrorAlert(const char * action, status_t err); 169 169 170 170 static void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_format & format); 171 static void NotifyRecordFile(void * cookie, int32code, ...);171 static void NotifyRecordFile(void * cookie, BMediaRecorder::notification code, ...); 172 172 173 173 static void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format); 174 174 static void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...); -
src/kits/media/Jamfile
diff --git a/src/kits/media/Jamfile b/src/kits/media/Jamfile index 583b12b..c1e1a87 100644
a b for architectureObject in [ MultiArchSubDirSetup ] { 20 20 # Private Media Kit 21 21 !missing_symbols.cpp 22 22 MediaRecorder.cpp 23 MediaRecorderNode.cpp24 23 25 24 # Public Media Kit 26 25 Buffer.cpp … … for architectureObject in [ MultiArchSubDirSetup ] { 58 57 DefaultMediaTheme.cpp 59 58 DormantNodeManager.cpp 60 59 FormatManager.cpp 60 MediaRecorderNode.cpp 61 61 Notifications.cpp 62 62 request_data.cpp 63 63 SharedBufferList.cpp … … for architectureObject in [ MultiArchSubDirSetup ] { 66 66 TimeSourceObject.cpp 67 67 TimeSourceObjectManager.cpp 68 68 SoundPlayNode.cpp 69 SoundUtils.cpp70 69 71 70 # Old (R3) Media Kit (built only for GCC2) 72 71 OldAudioModule.cpp -
src/kits/media/MediaRecorder.cpp
diff --git a/src/kits/media/MediaRecorder.cpp b/src/kits/media/MediaRecorder.cpp index 9c92909..d2d6be4 100644
a b 1 1 /* 2 * Copyright 1999, Be Incorporated2 * Copyright 2015, Hamish Morrison <hamishm53@gmail.com> 3 3 * Copyright 2014, Dario Casalinuovo 4 * Copyright 1999, Be Incorporated 4 5 * All Rights Reserved. 5 6 * This file may be used under the terms of the Be Sample Code License. 6 7 */ 7 8 8 9 9 #include "MediaRecorder.h"10 #include <MediaRecorder.h> 10 11 11 12 #include <MediaAddOn.h> 12 13 #include <MediaRoster.h> 13 14 #include <TimeSource.h> 14 15 15 #include "MediaDebug.h" 16 #include "MediaRecorderNode.h" 17 18 19 class MediaNodeReleaser { 20 public: 21 MediaNodeReleaser(media_node& mediaNode, 22 bool release = true) 23 : 24 fNode(mediaNode), 25 fRelease(release) 26 { 27 } 28 29 ~MediaNodeReleaser() 30 { 31 if (fRelease) 32 BMediaRoster::Roster()->ReleaseNode(fNode); 33 } 34 35 void SetTo(media_node& node) 36 { 37 fNode = node; 38 } 39 40 void SetRelease(bool release) 41 { 42 fRelease = release; 43 } 44 45 private: 46 media_node& fNode; 47 bool fRelease; 48 }; 16 #include <MediaDebug.h> 17 #include <MediaRecorderNode.h> 49 18 50 19 51 20 BMediaRecorder::BMediaRecorder(const char* name, media_type type) … … BMediaRecorder::BMediaRecorder(const char* name, media_type type) 53 22 fInitErr(B_OK), 54 23 fConnected(false), 55 24 fRunning(false), 56 f TimeSource(NULL),25 fReleaseOutputNode(false), 57 26 fRecordHook(NULL), 58 27 fNotifyHook(NULL), 59 28 fNode(NULL), … … BMediaRecorder::BMediaRecorder(const char* name, media_type type) 64 33 BMediaRoster::Roster(&fInitErr); 65 34 66 35 if (fInitErr == B_OK) { 67 fNode = new BMediaRecorderNode(name, this, type); 36 fNode = new(std::nothrow) BMediaRecorderNode(name, this, type); 37 if (fNode == NULL) 38 fInitErr = B_NO_MEMORY; 39 68 40 fInitErr = BMediaRoster::CurrentRoster()->RegisterNode(fNode); 69 41 } 70 42 } … … BMediaRecorder::~BMediaRecorder() 79 51 Disconnect(); 80 52 fNode->Release(); 81 53 } 82 83 if (fTimeSource != NULL)84 fTimeSource->Release();85 86 54 } 87 55 88 56 … … BMediaRecorder::BufferReceived(void* buffer, size_t size, 132 100 133 101 134 102 status_t 135 BMediaRecorder::Connect(const media_format& format , uint32 flags)103 BMediaRecorder::Connect(const media_format& format) 136 104 { 137 105 CALLED(); 138 106 … … BMediaRecorder::Connect(const media_format& format, uint32 flags) 142 110 if (fConnected) 143 111 return B_MEDIA_ALREADY_CONNECTED; 144 112 145 return _Connect(&format, flags, NULL, NULL, NULL); 113 status_t err = B_OK; 114 media_node node; 115 116 switch (format.type) { 117 // switch on format for default 118 case B_MEDIA_RAW_AUDIO: 119 err = BMediaRoster::Roster()->GetAudioMixer(&node); 120 break; 121 case B_MEDIA_RAW_VIDEO: 122 case B_MEDIA_ENCODED_VIDEO: 123 err = BMediaRoster::Roster()->GetVideoInput(&node); 124 break; 125 // give up? 126 default: 127 return B_MEDIA_BAD_FORMAT; 128 } 129 130 if (err != B_OK) 131 return err; 132 133 fReleaseOutputNode = true; 134 135 err = _Connect(node, NULL, format); 136 137 if (err != B_OK) { 138 BMediaRoster::Roster()->ReleaseNode(node); 139 fReleaseOutputNode = false; 140 } 141 142 return err; 146 143 } 147 144 148 145 149 146 status_t 150 BMediaRecorder::Connect(const dormant_node_info& dormant Info,151 const media_format * format, uint32 flags)147 BMediaRecorder::Connect(const dormant_node_info& dormantNode, 148 const media_format& format) 152 149 { 153 150 CALLED(); 154 151 … … BMediaRecorder::Connect(const dormant_node_info& dormantInfo, 158 155 if (fConnected) 159 156 return B_MEDIA_ALREADY_CONNECTED; 160 157 161 return _Connect(format, flags, &dormantInfo, NULL, NULL); 158 media_node node; 159 status_t err = BMediaRoster::Roster()->InstantiateDormantNode(dormantNode, 160 &node, B_FLAVOR_IS_GLOBAL); 161 162 if (err != B_OK) 163 return err; 164 165 fReleaseOutputNode = true; 166 167 err = _Connect(node, NULL, format); 168 169 if (err != B_OK) { 170 BMediaRoster::Roster()->ReleaseNode(node); 171 fReleaseOutputNode = false; 172 } 173 174 return err; 162 175 } 163 176 164 177 165 178 status_t 166 179 BMediaRecorder::Connect(const media_node& node, 167 const media_output* useOutput, const media_format* format, 168 uint32 flags) 180 const media_output* output, const media_format* format) 169 181 { 170 182 CALLED(); 171 183 … … BMediaRecorder::Connect(const media_node& node, 175 187 if (fConnected) 176 188 return B_MEDIA_ALREADY_CONNECTED; 177 189 178 return _Connect(format, flags, NULL, &node, useOutput); 190 if (format == NULL && output != NULL) 191 format = &output->format; 192 193 return _Connect(node, output, *format); 179 194 } 180 195 181 196 … … BMediaRecorder::Disconnect() 206 221 fOutputNode.node, fOutput.source, 207 222 fNode->Node().node, fInput.destination); 208 223 209 BMediaRoster::Roster()->ReleaseNode(fOutputNode); 210 211 if (fTimeSource != NULL) { 212 fTimeSource->Release(); 213 fTimeSource = NULL; 224 if (fReleaseOutputNode) { 225 BMediaRoster::Roster()->ReleaseNode(fOutputNode); 226 fReleaseOutputNode = false; 214 227 } 215 228 216 229 fConnected = false; … … BMediaRecorder::Start(bool force) 240 253 // start node here 241 254 status_t err = B_OK; 242 255 243 if ( fNode->Node().kind & B_TIME_SOURCE)256 if ((fOutputNode.kind & B_TIME_SOURCE) != 0) 244 257 err = BMediaRoster::CurrentRoster()->StartTimeSource( 245 258 fOutputNode, BTimeSource::RealTime()); 246 259 else 247 260 err = BMediaRoster::CurrentRoster()->StartNode( 248 fOutputNode, f TimeSource->Now());261 fOutputNode, fNode->TimeSource()->Now()); 249 262 250 263 // then un-mute it 251 264 if (err == B_OK) { … … BMediaRecorder::Format() const 327 340 328 341 329 342 status_t 330 BMediaRecorder::_Connect(const media_format* format, 331 uint32 flags, const dormant_node_info* dormantNode, 332 const media_node* mediaNode, const media_output* output) 343 BMediaRecorder::_Connect(const media_node& node, 344 const media_output* output, const media_format& format) 333 345 { 334 346 CALLED(); 335 347 336 348 status_t err = B_OK; 337 media_format ourFormat; 338 media_node node; 339 MediaNodeReleaser away(node, false); 349 media_format ourFormat = format; 340 350 media_output ourOutput; 341 351 342 // argument checking and set-up343 if (format != NULL)344 ourFormat = *format;345 346 352 if (fNode == NULL) 347 353 return B_ERROR; 348 354 349 if (mediaNode == NULL && output != NULL)350 return B_MISMATCHED_VALUES;351 352 if (dormantNode != NULL && (mediaNode != NULL || output != NULL))353 return B_MISMATCHED_VALUES;354 355 if (format == NULL && output != NULL)356 ourFormat = output->format;357 358 355 fNode->SetAcceptedFormat(ourFormat); 359 356 360 // figure out the node to instantiate361 if (dormantNode != NULL) {362 363 err = BMediaRoster::Roster()->InstantiateDormantNode(364 *dormantNode, &node, B_FLAVOR_IS_GLOBAL);365 366 away.SetRelease(true);367 368 } else if (mediaNode != NULL) {369 node = *mediaNode;370 } else {371 switch (ourFormat.type) {372 373 // switch on format for default374 case B_MEDIA_RAW_AUDIO:375 err = BMediaRoster::Roster()->GetAudioInput(&node);376 away.SetRelease(true);377 break;378 379 case B_MEDIA_RAW_VIDEO:380 case B_MEDIA_ENCODED_VIDEO:381 err = BMediaRoster::Roster()->GetVideoInput(&node);382 away.SetRelease(true);383 break;384 385 // give up?386 default:387 return B_MEDIA_BAD_FORMAT;388 break;389 }390 }391 392 357 fOutputNode = node; 393 358 394 359 // figure out the output provided 395 396 360 if (output != NULL) { 397 361 ourOutput = *output; 398 362 } else if (err == B_OK) { 399 400 363 media_output outputs[10]; 401 364 int32 count = 10; 402 365 403 err = BMediaRoster::Roster()->GetFreeOutputsFor( node,366 err = BMediaRoster::Roster()->GetFreeOutputsFor(fOutputNode, 404 367 outputs, count, &count, ourFormat.type); 405 368 406 369 if (err != B_OK) 407 370 return err; 408 371 409 err = B_MEDIA_BAD_SOURCE;410 411 372 for (int i = 0; i < count; i++) { 412 373 if (format_is_compatible(outputs[i].format, ourFormat)) { 413 374 ourOutput = outputs[i]; 414 err = B_OK;415 375 ourFormat = outputs[i].format; 416 376 break; 417 377 } 418 419 378 } 420 421 } else {422 return err;423 379 } 424 380 425 381 if (ourOutput.source == media_source::null) … … BMediaRecorder::_Connect(const media_format* format, 427 383 428 384 // find our Node's free input 429 385 media_input ourInput; 430 431 386 err = fNode->GetInput(&ourInput); 432 387 if (err != B_OK) 433 388 return err; 434 389 435 media_node time _source;436 if ( node.kind & B_TIME_SOURCE)437 time _source = node;390 media_node timeSource; 391 if ((node.kind & B_TIME_SOURCE) != 0) 392 timeSource = node; 438 393 else 439 BMediaRoster::Roster()->Get SystemTimeSource(&time_source);394 BMediaRoster::Roster()->GetTimeSource(&timeSource); 440 395 441 396 // set time source 442 BMediaRoster::Roster()->SetTimeSourceFor( 443 fNode->Node().node, time_source.node); 444 445 fTimeSource = BMediaRoster::CurrentRoster()->MakeTimeSourceFor( 446 fNode->Node()); 397 err = BMediaRoster::Roster()->SetTimeSourceFor(fNode->Node().node, 398 timeSource.node); 447 399 448 400 if (err != B_OK) 449 401 return err; 450 402 451 403 // start the recorder node (it's always running) 452 err = BMediaRoster::CurrentRoster()->StartNode( 453 f OutputNode, fTimeSource->Now());404 err = BMediaRoster::CurrentRoster()->StartNode(fOutputNode, 405 fNode->TimeSource()->Now()); 454 406 455 407 if (err != B_OK) 456 408 return err; … … BMediaRecorder::_Connect(const media_format* format, 467 419 return err; 468 420 469 421 fConnected = true; 470 away.SetRelease(false); 471 472 return err; 422 return B_OK; 473 423 } 424 425 426 void BMediaRecorder::_ReservedMediaRecorder0() { } 427 void BMediaRecorder::_ReservedMediaRecorder1() { } 428 void BMediaRecorder::_ReservedMediaRecorder2() { } 429 void BMediaRecorder::_ReservedMediaRecorder3() { } 430 void BMediaRecorder::_ReservedMediaRecorder4() { } 431 void BMediaRecorder::_ReservedMediaRecorder5() { } 432 void BMediaRecorder::_ReservedMediaRecorder6() { } 433 void BMediaRecorder::_ReservedMediaRecorder7() { } 434 -
src/kits/media/MediaRecorderNode.cpp
diff --git a/src/kits/media/MediaRecorderNode.cpp b/src/kits/media/MediaRecorderNode.cpp index b8c3f97..bb6d5be 100644
a b 1 1 /* 2 * Copyright 1999, Be Incorporated3 2 * Copyright 2014, Dario Casalinuovo 3 * Copyright 1999, Be Incorporated 4 4 * All Rights Reserved. 5 5 * This file may be used under the terms of the Be Sample Code License. 6 6 */ … … 13 13 #include <TimedEventQueue.h> 14 14 #include <TimeSource.h> 15 15 16 #include "MediaDebug.h"17 #include "MediaRecorder.h"16 #include <MediaDebug.h> 17 #include <MediaRecorder.h> 18 18 19 19 20 20 BMediaRecorderNode::BMediaRecorderNode(const char* name, … … BMediaRecorderNode::Start(bigtime_t performanceTime) 146 146 147 147 if (fRecorder->fNotifyHook) 148 148 (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie, 149 B _WILL_START, performanceTime);149 BMediaRecorder::B_WILL_START, performanceTime); 150 150 151 151 fRecorder->fRunning = true; 152 152 } … … BMediaRecorderNode::Stop(bigtime_t performanceTime, bool immediate) 159 159 160 160 if (fRecorder->fNotifyHook) 161 161 (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie, 162 B _WILL_STOP, performanceTime, immediate);162 BMediaRecorder::B_WILL_STOP, performanceTime, immediate); 163 163 164 164 fRecorder->fRunning = false; 165 165 } … … BMediaRecorderNode::Seek(bigtime_t mediaTime, bigtime_t performanceTime) 172 172 173 173 if (fRecorder->fNotifyHook) 174 174 (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie, 175 B _WILL_SEEK, performanceTime, mediaTime);175 BMediaRecorder::B_WILL_SEEK, performanceTime, mediaTime); 176 176 } 177 177 178 178 … … BMediaRecorderNode::TimeWarp(bigtime_t realTime, bigtime_t performanceTime) 185 185 // at them, so we can ignore the time warp as a consumer. 186 186 if (fRecorder->fNotifyHook) 187 187 (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie, 188 B _WILL_TIMEWARP, realTime, performanceTime);188 BMediaRecorder::B_WILL_TIMEWARP, realTime, performanceTime); 189 189 } 190 190 191 191 -
deleted file src/kits/media/SoundUtils.cpp
diff --git a/src/kits/media/SoundUtils.cpp b/src/kits/media/SoundUtils.cpp deleted file mode 100644 index 26908bc..0000000
+ - 1 /******************************************************************************2 /3 / File: SoundUtils.cpp4 /5 / Description: Utility functions for handling audio data.6 /7 / Copyright 1998-1999, Be Incorporated, All Rights Reserved8 /9 ******************************************************************************/10 11 #include <math.h>12 #include "SoundUtils.h"13 14 // These two conversions seem to pop up all the time in media code.15 // I guess it's the curse of microsecond resolution... ;-)16 double17 us_to_s(bigtime_t usecs)18 {19 return (usecs / 1000000.0);20 }21 22 bigtime_t23 s_to_us(double secs)24 {25 return (bigtime_t) (secs * 1000000.0);26 }27 28 int29 bytes_per_frame(30 const media_raw_audio_format & format)31 {32 // The media_raw_audio_format format constants encode the33 // bytes-per-sample value in the low nybble. Having a fixed34 // number of bytes-per-sample, and no inter-sample relationships,35 // is what makes a format "raw".36 int bytesPerSample = format.format & 0xf;37 return bytesPerSample * format.channel_count;38 }39 40 int41 frames_per_buffer(42 const media_raw_audio_format & format)43 {44 // This will give us the number of full-sized frames that will fit45 // in a buffer. (Remember, integer division automatically rounds46 // down.)47 int frames = 0;48 if (bytes_per_frame(format) > 0) {49 frames = format.buffer_size / bytes_per_frame(format);50 }51 return frames;52 }53 54 bigtime_t55 buffer_duration(56 const media_raw_audio_format & format)57 {58 // Figuring out duration is easy. We take extra precaution to59 // not divide by zero or return irrelevant results.60 bigtime_t duration = 0;61 if (format.buffer_size > 0 && format.frame_rate > 062 && bytes_per_frame(format) > 0) {63 // In these kinds of calculations, it's always useful to double-check64 // the unit conversions. (Anyone remember high school physics?)65 // bytes/(bytes/frame) / frames/sec66 // = frames * sec/frames67 // = secs which is what we want.68 duration = s_to_us((format.buffer_size / bytes_per_frame(format))69 / format.frame_rate);70 }71 return duration;72 }73 74 bigtime_t75 frames_duration(76 const media_raw_audio_format & format, int64 num_frames)77 {78 // Tells us how long in us it will take to produce num_frames,79 // with the given format.80 bigtime_t duration = 0;81 if (format.frame_rate > 0) {82 duration = s_to_us(num_frames/format.frame_rate);83 }84 return duration;85 }86 87 int88 buffers_for_duration(89 const media_raw_audio_format & format, bigtime_t duration)90 {91 // Double-checking those unit conversions again:92 // secs * ( (frames/sec) / (frames/buffer) ) = secs * (buffers/sec)93 // = buffers94 int buffers = 0;95 if (frames_per_buffer(format) > 0) {96 buffers = (int) ceil(us_to_s(duration)97 *(format.frame_rate/frames_per_buffer(format)));98 }99 return buffers;100 }101 102 int64103 frames_for_duration(104 const media_raw_audio_format & format, bigtime_t duration)105 {106 return (int64) ceil(format.frame_rate*us_to_s(duration));107 }