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 hamish, 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  
    66#define _MEDIA_RECORDER_H
    77
    88
     9#include <MediaDefs.h>
    910#include <MediaNode.h>
    10 #include <TimeSource.h>
    11 
    12 #include "MediaRecorderNode.h"
    13 #include "SoundUtils.h"
    1411
    1512
    1613namespace BPrivate { namespace media {
    1714
     15
     16class BMediaRecorderNode;
     17
    1818class BMediaRecorder {
    1919public:
     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
     34public:
    2035                                BMediaRecorder(const char* name,
    2136                                    media_type type
    2237                                        = B_MEDIA_UNKNOWN_TYPE);
    public:  
    2540
    2641            status_t            InitCheck() const;
    2742
    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 
    3643            status_t            SetHooks(ProcessFunc recordFunc = NULL,
    3744                                    NotifyFunc notifyFunc = NULL,
    3845                                    void* cookie = NULL);
    public:  
    4350    virtual status_t            Start(bool force = false);
    4451    virtual status_t            Stop(bool force = false);
    4552
    46     virtual status_t            Connect(const media_format& format,
    47                                     uint32 flags = 0);
     53    virtual status_t            Connect(const media_format& format);
    4854
    4955    virtual status_t            Connect(const dormant_node_info& dormantInfo,
    50                                     const media_format* format = NULL,
    51                                     uint32 flags = 0);
     56                                    const media_format& format);
    5257
    5358    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);
    5761
    5862    virtual status_t            Disconnect();
    5963
    public:  
    6771
    6872protected:
    6973
    70     virtual void                BufferReceived(void* buffer,
    71                                     size_t size,
     74    virtual void                BufferReceived(void* buffer, size_t size,
    7275                                    const media_header& header);
    7376private:
    7477
    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);
    8181
    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();
    8390
    84         bool                    fConnected;
    85         bool                    fRunning;
     91            status_t            fInitErr;
    8692
    87         BTimeSource*            fTimeSource;
     93            bool                fConnected;
     94            bool                fRunning;
     95            bool                fReleaseOutputNode;
    8896
    89         ProcessFunc             fRecordHook;
    90         NotifyFunc              fNotifyHook;
     97            ProcessFunc         fRecordHook;
     98            NotifyFunc          fNotifyHook;
    9199
    92         media_node              fOutputNode;
    93         media_output            fOutput;
     100            media_node          fOutputNode;
     101            media_output        fOutput;
    94102
    95         BMediaRecorderNode*     fNode;
    96         media_input             fInput;
     103            BMediaRecorderNode* fNode;
     104            media_input         fInput;
    97105
    98         void*                   fBufferCookie;
     106            void*               fBufferCookie;
     107            uint32              fPadding[32];
    99108
    100         friend class            BMediaRecorderNode;
     109            friend class        BMediaRecorderNode;
    101110};
    102111
    103112}
  • 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  
    11/*
    2  * Copyright 1999, Be Incorporated
    32 * Copyright 2014, Dario Casalinuovo
     3 * Copyright 1999, Be Incorporated
    44 * All Rights Reserved.
    55 * This file may be used under the terms of the Be Sample Code License.
    66 */
    protected:  
    7676    virtual void            BufferReceived(BBuffer* buffer);
    7777
    7878    virtual void            ProducerDataStatus(
    79                                 const media_destination& forWhom,
     79                                const media_destination& destination,
    8080                                int32 status,
    8181                                bigtime_t performanceTime);
    8282
    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);
    8786
    88     virtual status_t        Connected(
    89                                 const media_source& producer,
     87    virtual status_t        Connected(const media_source& producer,
    9088                                const media_destination& where,
    91                                 const media_format& withFormat,
     89                                const media_format& format,
    9290                                media_input* outInput);
    9391
    94     virtual void            Disconnected(
    95                                 const media_source& producer,
     92    virtual void            Disconnected(const media_source& producer,
    9693                                const media_destination& where);
    9794
    98     virtual status_t        FormatChanged(
    99                                 const media_source& producer,
     95    virtual status_t        FormatChanged(const media_source& producer,
    10096                                const media_destination& consumer,
    10197                                int32 tag,
    10298                                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.h
    4 /
    5 /   Description:    Utility functions for handling audio data.
    6 /
    7 /   Copyright 1998-1999, Be Incorporated, All Rights Reserved
    8 /
    9 *******************************************************************************/
    10 
    11 #if ! defined( _SoundUtils_h )
    12 #define _SoundUtils_h
    13 
    14 #include <MediaDefs.h>
    15 
    16 //  Simple helper functions that come in handy when doing
    17 //  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 for
    32 //  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 Notify
    40 //  function hook.
    41 enum {
    42     B_WILL_START = 1,       //  performance_time
    43     B_WILL_STOP,            //  performance_time immediate
    44     B_WILL_SEEK,            //  performance_time media_time
    45     B_WILL_TIMEWARP,        //  real_time performance_time
    46     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 only
    52     B_PRODUCER_DATA_STATUS, //  status performance_time -- Consumer only
    53     B_LATE_NOTICE           //  how_much performance_time -- Producer only
    54 };
    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  
    11/*
    2  * Copyright 2005, Jérôme Duval. All rights reserved.
    32 * Copyright 2014, Dario Casalinuovo. All rights reserved.
     3 * Copyright 2005, Jérôme Duval. All rights reserved.
    44 * Distributed under the terms of the MIT License.
    55 *
    66 * Inspired by SoundCapture from Be newsletter (Media Kit Basics:
     
    4343#include <TimeSource.h>
    4444#include <NodeInfo.h>
    4545
    46 #include "SoundUtils.h"
    4746#include "RecorderWindow.h"
    4847#include "FileUtils.h"
    4948
    RecorderWindow::RecordFile(void* cookie, bigtime_t timestamp,  
    12241223
    12251224
    12261225void
    1227 RecorderWindow::NotifyRecordFile(void * cookie, int32 code, ...)
     1226RecorderWindow::NotifyRecordFile(void * cookie,
     1227    BMediaRecorder::notification code, ...)
    12281228{
    1229     if ((code == B_WILL_STOP) || (code == B_NODE_DIES)) {
     1229    if (code == BMediaRecorder::B_WILL_STOP) {
    12301230        RecorderWindow * window = (RecorderWindow *)cookie;
    12311231        // Tell the window we've stopped, if it doesn't
    12321232        // 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:  
    168168        void ErrorAlert(const char * action, status_t err);
    169169
    170170static  void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_format & format);
    171 static  void NotifyRecordFile(void * cookie, int32 code, ...);
     171static  void NotifyRecordFile(void * cookie, BMediaRecorder::notification code, ...);
    172172
    173173static  void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
    174174static  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 ] {  
    2020            # Private Media Kit
    2121            !missing_symbols.cpp
    2222            MediaRecorder.cpp
    23             MediaRecorderNode.cpp
    2423
    2524            # Public Media Kit
    2625            Buffer.cpp
    for architectureObject in [ MultiArchSubDirSetup ] {  
    5857            DefaultMediaTheme.cpp
    5958            DormantNodeManager.cpp
    6059            FormatManager.cpp
     60            MediaRecorderNode.cpp
    6161            Notifications.cpp
    6262            request_data.cpp
    6363            SharedBufferList.cpp
    for architectureObject in [ MultiArchSubDirSetup ] {  
    6666            TimeSourceObject.cpp
    6767            TimeSourceObjectManager.cpp
    6868            SoundPlayNode.cpp
    69             SoundUtils.cpp
    7069
    7170            # Old (R3) Media Kit (built only for GCC2)
    7271            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  
    11/*
    2  * Copyright 1999, Be Incorporated
     2 * Copyright 2015, Hamish Morrison <hamishm53@gmail.com>
    33 * Copyright 2014, Dario Casalinuovo
     4 * Copyright 1999, Be Incorporated
    45 * All Rights Reserved.
    56 * This file may be used under the terms of the Be Sample Code License.
    67 */
    78
    89
    9 #include "MediaRecorder.h"
     10#include <MediaRecorder.h>
    1011
    1112#include <MediaAddOn.h>
    1213#include <MediaRoster.h>
    1314#include <TimeSource.h>
    1415
    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>
    4918
    5019
    5120BMediaRecorder::BMediaRecorder(const char* name, media_type type)
    BMediaRecorder::BMediaRecorder(const char* name, media_type type)  
    5322    fInitErr(B_OK),
    5423    fConnected(false),
    5524    fRunning(false),
    56     fTimeSource(NULL),
     25    fReleaseOutputNode(false),
    5726    fRecordHook(NULL),
    5827    fNotifyHook(NULL),
    5928    fNode(NULL),
    BMediaRecorder::BMediaRecorder(const char* name, media_type type)  
    6433    BMediaRoster::Roster(&fInitErr);
    6534
    6635    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
    6840        fInitErr = BMediaRoster::CurrentRoster()->RegisterNode(fNode);
    6941    }
    7042}
    BMediaRecorder::~BMediaRecorder()  
    7951        Disconnect();
    8052        fNode->Release();
    8153    }
    82 
    83     if (fTimeSource != NULL)
    84         fTimeSource->Release();
    85 
    8654}
    8755
    8856
    BMediaRecorder::BufferReceived(void* buffer, size_t size,  
    132100
    133101
    134102status_t
    135 BMediaRecorder::Connect(const media_format& format, uint32 flags)
     103BMediaRecorder::Connect(const media_format& format)
    136104{
    137105    CALLED();
    138106
    BMediaRecorder::Connect(const media_format& format, uint32 flags)  
    142110    if (fConnected)
    143111        return B_MEDIA_ALREADY_CONNECTED;
    144112
    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;
    146143}
    147144
    148145
    149146status_t
    150 BMediaRecorder::Connect(const dormant_node_info& dormantInfo,
    151     const media_format* format, uint32 flags)
     147BMediaRecorder::Connect(const dormant_node_info& dormantNode,
     148    const media_format& format)
    152149{
    153150    CALLED();
    154151
    BMediaRecorder::Connect(const dormant_node_info& dormantInfo,  
    158155    if (fConnected)
    159156        return B_MEDIA_ALREADY_CONNECTED;
    160157
    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;
    162175}
    163176
    164177
    165178status_t
    166179BMediaRecorder::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)
    169181{
    170182    CALLED();
    171183
    BMediaRecorder::Connect(const media_node& node,  
    175187    if (fConnected)
    176188        return B_MEDIA_ALREADY_CONNECTED;
    177189
    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);
    179194}
    180195
    181196
    BMediaRecorder::Disconnect()  
    206221        fOutputNode.node, fOutput.source,
    207222            fNode->Node().node, fInput.destination);
    208223
    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;
    214227    }
    215228
    216229    fConnected = false;
    BMediaRecorder::Start(bool force)  
    240253    // start node here
    241254    status_t err = B_OK;
    242255
    243     if (fNode->Node().kind & B_TIME_SOURCE)
     256    if ((fOutputNode.kind & B_TIME_SOURCE) != 0)
    244257        err = BMediaRoster::CurrentRoster()->StartTimeSource(
    245258            fOutputNode, BTimeSource::RealTime());
    246259    else
    247260        err = BMediaRoster::CurrentRoster()->StartNode(
    248             fOutputNode, fTimeSource->Now());
     261            fOutputNode, fNode->TimeSource()->Now());
    249262
    250263    // then un-mute it
    251264    if (err == B_OK) {
    BMediaRecorder::Format() const  
    327340
    328341
    329342status_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)
     343BMediaRecorder::_Connect(const media_node& node,
     344    const media_output* output, const media_format& format)
    333345{
    334346    CALLED();
    335347
    336348    status_t err = B_OK;
    337     media_format ourFormat;
    338     media_node node;
    339     MediaNodeReleaser away(node, false);
     349    media_format ourFormat = format;
    340350    media_output ourOutput;
    341351
    342     // argument checking and set-up
    343     if (format != NULL)
    344         ourFormat = *format;
    345 
    346352    if (fNode == NULL)
    347353        return B_ERROR;
    348354
    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 
    358355    fNode->SetAcceptedFormat(ourFormat);
    359356
    360     // figure out the node to instantiate
    361     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 default
    374             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 
    392357    fOutputNode = node;
    393358
    394359    // figure out the output provided
    395 
    396360    if (output != NULL) {
    397361        ourOutput = *output;
    398362    } else if (err == B_OK) {
    399 
    400363        media_output outputs[10];
    401364        int32 count = 10;
    402365
    403         err = BMediaRoster::Roster()->GetFreeOutputsFor(node,
     366        err = BMediaRoster::Roster()->GetFreeOutputsFor(fOutputNode,
    404367            outputs, count, &count, ourFormat.type);
    405368
    406369        if (err != B_OK)
    407370            return err;
    408371
    409         err = B_MEDIA_BAD_SOURCE;
    410 
    411372        for (int i = 0; i < count; i++) {
    412373            if (format_is_compatible(outputs[i].format, ourFormat)) {
    413374                ourOutput = outputs[i];
    414                 err = B_OK;
    415375                ourFormat = outputs[i].format;
    416376                break;
    417377            }
    418 
    419378        }
    420 
    421     } else {
    422         return err;
    423379    }
    424380
    425381    if (ourOutput.source == media_source::null)
    BMediaRecorder::_Connect(const media_format* format,  
    427383
    428384    // find our Node's free input
    429385    media_input ourInput;
    430 
    431386    err = fNode->GetInput(&ourInput);
    432387    if (err != B_OK)
    433388        return err;
    434389
    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;
    438393    else
    439         BMediaRoster::Roster()->GetSystemTimeSource(&time_source);
     394        BMediaRoster::Roster()->GetTimeSource(&timeSource);
    440395
    441396    // 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);
    447399
    448400    if (err != B_OK)
    449401        return err;
    450402
    451403    // start the recorder node (it's always running)
    452     err = BMediaRoster::CurrentRoster()->StartNode(
    453         fOutputNode, fTimeSource->Now());
     404    err = BMediaRoster::CurrentRoster()->StartNode(fOutputNode,
     405        fNode->TimeSource()->Now());
    454406
    455407    if (err != B_OK)
    456408        return err;
    BMediaRecorder::_Connect(const media_format* format,  
    467419        return err;
    468420
    469421    fConnected = true;
    470     away.SetRelease(false);
    471 
    472     return err;
     422    return B_OK;
    473423}
     424
     425
     426void BMediaRecorder::_ReservedMediaRecorder0() { }
     427void BMediaRecorder::_ReservedMediaRecorder1() { }
     428void BMediaRecorder::_ReservedMediaRecorder2() { }
     429void BMediaRecorder::_ReservedMediaRecorder3() { }
     430void BMediaRecorder::_ReservedMediaRecorder4() { }
     431void BMediaRecorder::_ReservedMediaRecorder5() { }
     432void BMediaRecorder::_ReservedMediaRecorder6() { }
     433void 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  
    11/*
    2  * Copyright 1999, Be Incorporated
    32 * Copyright 2014, Dario Casalinuovo
     3 * Copyright 1999, Be Incorporated
    44 * All Rights Reserved.
    55 * This file may be used under the terms of the Be Sample Code License.
    66 */
     
    1313#include <TimedEventQueue.h>
    1414#include <TimeSource.h>
    1515
    16 #include "MediaDebug.h"
    17 #include "MediaRecorder.h"
     16#include <MediaDebug.h>
     17#include <MediaRecorder.h>
    1818
    1919
    2020BMediaRecorderNode::BMediaRecorderNode(const char* name,
    BMediaRecorderNode::Start(bigtime_t performanceTime)  
    146146
    147147    if (fRecorder->fNotifyHook)
    148148        (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie,
    149             B_WILL_START, performanceTime);
     149            BMediaRecorder::B_WILL_START, performanceTime);
    150150
    151151    fRecorder->fRunning = true;
    152152}
    BMediaRecorderNode::Stop(bigtime_t performanceTime, bool immediate)  
    159159
    160160    if (fRecorder->fNotifyHook)
    161161        (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie,
    162             B_WILL_STOP, performanceTime, immediate);
     162            BMediaRecorder::B_WILL_STOP, performanceTime, immediate);
    163163
    164164    fRecorder->fRunning = false;
    165165}
    BMediaRecorderNode::Seek(bigtime_t mediaTime, bigtime_t performanceTime)  
    172172
    173173    if (fRecorder->fNotifyHook)
    174174        (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie,
    175             B_WILL_SEEK, performanceTime, mediaTime);
     175            BMediaRecorder::B_WILL_SEEK, performanceTime, mediaTime);
    176176}
    177177
    178178
    BMediaRecorderNode::TimeWarp(bigtime_t realTime, bigtime_t performanceTime)  
    185185    // at them, so we can ignore the time warp as a consumer.
    186186    if (fRecorder->fNotifyHook)
    187187        (*fRecorder->fNotifyHook)(fRecorder->fBufferCookie,
    188             B_WILL_TIMEWARP, realTime, performanceTime);
     188            BMediaRecorder::B_WILL_TIMEWARP, realTime, performanceTime);
    189189}
    190190
    191191
  • 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.cpp
    4 /
    5 /   Description:    Utility functions for handling audio data.
    6 /
    7 /   Copyright 1998-1999, Be Incorporated, All Rights Reserved
    8 /
    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 double
    17 us_to_s(bigtime_t usecs)
    18 {
    19     return (usecs / 1000000.0);
    20 }
    21 
    22 bigtime_t
    23 s_to_us(double secs)
    24 {
    25     return (bigtime_t) (secs * 1000000.0);
    26 }
    27 
    28 int
    29 bytes_per_frame(
    30     const media_raw_audio_format & format)
    31 {
    32     //  The media_raw_audio_format format constants encode the
    33     //  bytes-per-sample value in the low nybble. Having a fixed
    34     //  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 int
    41 frames_per_buffer(
    42     const media_raw_audio_format & format)
    43 {
    44     // This will give us the number of full-sized frames that will fit
    45     // in a buffer. (Remember, integer division automatically rounds
    46     // 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_t
    55 buffer_duration(
    56     const media_raw_audio_format & format)
    57 {
    58     //  Figuring out duration is easy. We take extra precaution to
    59     //  not divide by zero or return irrelevant results.
    60     bigtime_t duration = 0;
    61     if (format.buffer_size > 0 && format.frame_rate > 0
    62         && bytes_per_frame(format) > 0) {
    63         //  In these kinds of calculations, it's always useful to double-check
    64         //  the unit conversions. (Anyone remember high school physics?)
    65         //  bytes/(bytes/frame) / frames/sec
    66         //  = frames * sec/frames
    67         //  = 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_t
    75 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 int
    88 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     // = buffers
    94     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 int64
    103 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 }