Ticket #2970: media.2.diff

File media.2.diff, 25.8 KB (added by modeenf, 8 years ago)
  • headers/os/media/MediaEncoder.h

    diff --git a/headers/os/media/MediaEncoder.h b/headers/os/media/MediaEncoder.h
    index 834bc73..dc44cbd 100644
    a b  
    88
    99#include <MediaFormats.h>
    1010
     11namespace BPrivate {
     12    class Encoder;
     13}
     14
     15namespace BPrivate {
     16    namespace media {
     17        class Encoder;
     18        class EncoderPlugin;
     19    }
     20}
     21
    1122
    1223class BMediaEncoder {
    1324public:
    private:  
    6576            BMediaEncoder&      operator=(const BMediaEncoder& other);
    6677
    6778private:
     79            status_t            _AttachToEncoder();
     80
    6881    static  status_t            write_chunk(void* classPtr,
    6982                                    const void* buffer, size_t size,
    7083                                    media_encode_info* info);
    private:  
    7386            void                ReleaseEncoder();
    7487
    7588            uint32              _reserved_was_fEncoderMgr;
    76             uint32              _reserved_was_fEncoder;
     89            BPrivate::media::Encoder*   fEncoder;
    7790
    7891            int32               fEncoderID;
    7992            bool                fFormatValid;
  • headers/private/media/EncoderPlugin.h

    diff --git a/headers/private/media/EncoderPlugin.h b/headers/private/media/EncoderPlugin.h
    index dabcdf1..b5bc8c6 100644
    a b  
    11/*
    2  * Copyright 2009, Haiku Inc. All rights reserved.
     2 * Copyright 2009-2012, Haiku Inc. All rights reserved.
    33 * Distributed under the terms of the MIT license.
    44 */
    55#ifndef _ENCODER_PLUGIN_H
    public:  
    122122    virtual Encoder*            NewEncoder(
    123123                                    const media_codec_info& codecInfo) = 0;
    124124
     125    virtual Encoder*            NewEncoder(
     126                                    const media_format& format) = 0;
     127
    125128    virtual status_t            RegisterNextEncoder(int32* cookie,
    126129                                    media_codec_info* codecInfo,
    127130                                    media_format_family* formatFamily,
  • headers/private/media/PluginManager.h

    diff --git a/headers/private/media/PluginManager.h b/headers/private/media/PluginManager.h
    index d74cba3..5cca4e9 100644
    a b  
    11/*
    22 * Copyright 2004-2007, Marcus Overhagen. All rights reserved.
    3  * Distributed under the terms of the OpenBeOS License.
     3 * Copyright 2012, Fredrik Modéen, firstnam@lastname.se.
     4 * Distributed under the terms of the MIT License.
    45 */
    56#ifndef _PLUGIN_MANAGER_H
    67#define _PLUGIN_MANAGER_H
    public:  
    5152            status_t            CreateEncoder(Encoder** encoder,
    5253                                    const media_codec_info* codecInfo,
    5354                                    uint32 flags);
     55                                   
     56            status_t            CreateEncoder(Encoder** encoder,
     57                                    const media_format& format);
     58           
    5459            void                DestroyEncoder(Encoder* encoder);
    5560   
    5661private:
  • headers/private/media/ServerInterface.h

    diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
    index 2c28980..3e423ce 100644
    a b  
    11/*
    22 * Copyright 2002, Marcus Overhagen. All Rights Reserved.
    33 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
     4 * Copyright 2012, Fredrik Modéen, firstnam@lastname.se.
    45 * Distributed under the terms of the MIT License.
    56 */
    67#ifndef _SERVER_INTERFACE_H_
    enum {  
    7879    SERVER_GET_DESCRIPTION_FOR_FORMAT,
    7980    SERVER_GET_READERS,
    8081    SERVER_GET_DECODER_FOR_FORMAT,
     82    SERVER_GET_DECODER_FOR_CODEC_INFO,
    8183    SERVER_GET_WRITER_FOR_FORMAT_FAMILY,
    8284    SERVER_GET_FILE_FORMAT_FOR_COOKIE,
    8385    SERVER_GET_CODEC_INFO_FOR_COOKIE,
    8486    SERVER_GET_ENCODER_FOR_CODEC_INFO,
     87    SERVER_GET_ENCODER_FOR_FORMAT,
    8588    SERVER_REGISTER_ADD_ON,
    8689    SERVER_UNREGISTER_ADD_ON,
    8790    SERVER_GET_ADD_ON_REF,
    struct server_get_decoder_for_format_reply : reply_data {  
    610613        // a ref to the decoder
    611614};
    612615
     616struct server_get_decoder_for_codec_info_request : request_data {
     617    int32                   id;
     618};
     619
     620struct server_get_decoder_for_codec_info_reply : reply_data {
     621    xfer_entry_ref          ref;
     622        // a ref to the encoder
     623};
     624
    613625struct server_get_encoder_for_codec_info_request : request_data {
    614626    int32                   id;
    615627};
    struct server_get_encoder_for_codec_info_reply : reply_data {  
    619631        // a ref to the encoder
    620632};
    621633
     634struct server_get_encoder_for_format_request : request_data {
     635    media_format            format;
     636};
     637
     638struct server_get_encoder_for_format_reply : reply_data {
     639    xfer_entry_ref          ref;
     640        // a ref to the decoder
     641};
     642
    622643struct server_get_readers_request : request_data {
    623644};
    624645
  • src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp

    diff --git a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp
    index b17304b..f779fc1 100644
    a b FFmpegPlugin::NewEncoder(const media_codec_info& codecInfo)  
    156156}
    157157
    158158
     159Encoder*
     160FFmpegPlugin::NewEncoder(const media_format& format)
     161{
     162/*  for (size_t i = 0; i < gEncoderCount; i++) {
     163        if (codecInfo.sub_id == gEncoderTable[i].codec_info.sub_id) {
     164            return new(std::nothrow)AVCodecEncoder(codecInfo.sub_id,
     165                gEncoderTable[i].bit_rate_scale);
     166        }
     167    }*/
     168    return NULL;
     169}
     170
     171
    159172status_t
    160173FFmpegPlugin::RegisterNextEncoder(int32* cookie, media_codec_info* _codecInfo,
    161174    media_format_family* _formatFamily, media_format* _inputFormat,
  • src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h

    diff --git a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h
    index ef37a5f..360a857 100644
    a b public:  
    3434
    3535    virtual Encoder*            NewEncoder(
    3636                                    const media_codec_info& codecInfo);
     37   
     38    virtual Encoder*            NewEncoder(const media_format& format);
     39   
    3740    virtual status_t            RegisterNextEncoder(int32* cookie,
    3841                                    media_codec_info* codecInfo,
    3942                                    media_format_family* formatFamily,
  • src/kits/media/DataExchange.cpp

    diff --git a/src/kits/media/DataExchange.cpp b/src/kits/media/DataExchange.cpp
    index dcf3eeb..a76c91b 100644
    a b  
    11/*
    22 * Copyright 2002-2007, Marcus Overhagen. All rights reserved.
     3 * Copyright 2012, Fredrik Modéen, [firstname]@[lastname].se.
    34 * Distributed under the terms of the MIT License.
    45 */
    56
    find_media_server_port()  
    3940    if (sMediaServerPort < 0) {
    4041        TRACE("couldn't find sMediaServerPort\n");
    4142        sMediaServerPort = BAD_MEDIA_SERVER_PORT; // make this a unique number
    42     }
     43    } else
     44        TRACE("Did find sMediaServerPort (%ld)\n", sMediaServerPort);
    4345}
    4446
    4547
    find_media_addon_server_port()  
    5052    if (sMediaAddonServerPort < 0) {
    5153        TRACE("couldn't find sMediaAddonServerPort\n");
    5254        sMediaAddonServerPort = BAD_MEDIA_ADDON_SERVER_PORT; // make this a unique number
    53     }
     55    } else
     56        TRACE("Did find MediaAddonServerPort (%ld)\n", sMediaAddonServerPort);
    5457}
    5558
    5659
  • src/kits/media/MediaEncoder.cpp

    diff --git a/src/kits/media/MediaEncoder.cpp b/src/kits/media/MediaEncoder.cpp
    index 6084920..1ee38d4 100644
    a b  
    1 /***********************************************************************
    2  * AUTHOR: Marcus Overhagen
    3  *   FILE: MediaEncoder.cpp
    4  *  DESCR:
    5  ***********************************************************************/
     1/*
     2 * Copyright 2004-2007, Marcus Overhagen. All rights reserved.
     3 * Copyright 2010, Oleg Krysenkov, beos344@mail.ru.
     4 * Copyright 2012, Fredrik Modéen, [firstname]@[lastname].se.
     5 * Distributed under the terms of the MIT License.
     6 */
     7
     8/*TO DO SetTo, SetFormat, Enode Class*/
     9
     10
    611#include <MediaEncoder.h>
     12#include <EncoderPlugin.h>
     13#include <PluginManager.h>
     14#include <new>
    715#include "debug.h"
    816
    917
     
    1220 *************************************************************/
    1321
    1422BMediaEncoder::BMediaEncoder()
     23    :   fEncoder(NULL),
     24        fInitStatus(B_NO_INIT)
    1525{
    16     UNIMPLEMENTED();
     26
    1727}
    1828
    1929
    2030BMediaEncoder::BMediaEncoder(const media_format *output_format)
     31    :   fEncoder(NULL),
     32        fInitStatus(B_NO_INIT)
    2133{
    22     UNIMPLEMENTED();
     34    SetTo(output_format);
    2335}
    2436
    2537
    2638BMediaEncoder::BMediaEncoder(const media_codec_info *mci)
     39    :   fEncoder(NULL),
     40        fInitStatus(B_NO_INIT)
    2741{
    28     UNIMPLEMENTED();
     42    SetTo(mci);
    2943}
    3044
    3145
    3246/* virtual */
    3347BMediaEncoder::~BMediaEncoder()
    3448{
    35     UNIMPLEMENTED();
     49    gPluginManager.DestroyEncoder(fEncoder);
     50    fEncoder = NULL;
    3651}
    3752
    3853
    3954status_t
    4055BMediaEncoder::InitCheck() const
    4156{
    42     UNIMPLEMENTED();
    43 
    44     return B_OK;
     57    return fInitStatus;
    4558}
    4659
     60
    4761status_t
    4862BMediaEncoder::SetTo(const media_format *output_format)
    4963{
    50     UNIMPLEMENTED();
     64    gPluginManager.DestroyEncoder(fEncoder);
     65    fEncoder = NULL;
     66
     67    status_t err = gPluginManager.CreateEncoder(&fEncoder, *output_format);
     68    if (err < B_OK)
     69        goto fail;
     70
     71    err = _AttachToEncoder();
     72    if (err < B_OK)
     73        goto fail;
     74
     75/*  err = SetFormat(NULL, output_format); //Looked at BMediaDecoder
     76    if (err < B_OK)
     77        goto fail;
     78*/
     79    fInitStatus = B_OK;
    5180    return B_OK;
     81
     82fail:
     83    gPluginManager.DestroyEncoder(fEncoder);
     84    fEncoder = NULL;
     85    fInitStatus = B_NO_INIT;
     86    return err;
    5287}
    5388
     89
    5490status_t
    5591BMediaEncoder::SetTo(const media_codec_info *mci)
    5692{
    57     UNIMPLEMENTED();
     93    gPluginManager.DestroyEncoder(fEncoder);
     94    fEncoder = NULL;
     95
     96    status_t err = gPluginManager.CreateEncoder(&fEncoder, mci, 0);
     97    if (err < B_OK)
     98        goto fail;
     99
     100    err = _AttachToEncoder();
     101    if (err < B_OK)
     102        goto fail;
     103
     104    fInitStatus = B_OK;
    58105    return B_OK;
     106
     107fail:
     108    gPluginManager.DestroyEncoder(fEncoder);
     109    fEncoder = NULL;
     110    fInitStatus = B_NO_INIT;
     111    return err;
    59112}
    60113
    61114
    BMediaEncoder::SetFormat(media_format *input_format,  
    64117                         media_format *output_format,
    65118                         media_file_format *mfi)
    66119{
    67     UNIMPLEMENTED();
    68     return B_OK;
     120    TRACE("BMediaEncoder::SetFormat. Input = %d, Output = %d\n",
     121        input_format->type, output_format->type);
     122   
     123    if (!fEncoder)
     124        return B_NO_INIT;
     125
     126    UNIMPLEMENTED();   
     127
     128//  media_format in_format = *input_format;
     129//  media_format out_format = *output_format;
     130   
     131//  fEncoder->Setup(input_format, output_format, mfi);
     132   
     133    return B_OK;
    69134}
    70135
     136
    71137status_t
    72138BMediaEncoder::Encode(const void *buffer,
    73139                      int64 frame_count,
    74140                      media_encode_info *info)
    75141{
    76     UNIMPLEMENTED();
    77     return B_OK;
     142    if (!fEncoder)
     143        return B_NO_INIT;
     144
     145    return fEncoder->Encode(buffer, frame_count, info);
    78146}
    79147
    80148
    81149status_t
    82150BMediaEncoder::GetEncodeParameters(encode_parameters *parameters) const
    83151{
    84     UNIMPLEMENTED();
    85     return B_OK;
     152    if (fEncoder == NULL)
     153        return B_NO_INIT;
     154    else
     155        return fEncoder->GetEncodeParameters(parameters);
    86156}
    87157
    88158
    89159status_t
    90160BMediaEncoder::SetEncodeParameters(encode_parameters *parameters)
    91161{
    92     UNIMPLEMENTED();
    93     return B_OK;
     162    if (fEncoder == NULL)
     163        return B_NO_INIT;
     164    else
     165        return fEncoder->SetEncodeParameters(parameters);
    94166}
    95167
    96168
    BMediaEncoder::SetEncodeParameters(encode_parameters *parameters)  
    101173/* virtual */ status_t
    102174BMediaEncoder::AddTrackInfo(uint32 code, const char *data, size_t size)
    103175{
    104     UNIMPLEMENTED();
    105     return B_OK;
     176    if (fEncoder == NULL)
     177        return B_NO_INIT;
     178    else
     179        return fEncoder->AddTrackInfo(code, data, size);
    106180}
    107181
    108182
    BMediaEncoder::ReleaseEncoder()  
    140214    UNIMPLEMENTED();
    141215}
    142216
     217
     218status_t
     219BMediaEncoder::_AttachToEncoder()
     220{
     221    class MediaEncoderChunkWriter : public ChunkWriter {
     222    private:
     223        BMediaEncoder* fEncoder;
     224    public:
     225        MediaEncoderChunkWriter(BMediaEncoder* encoder)
     226        {
     227            fEncoder = encoder;
     228        }
     229        virtual status_t WriteChunk(const void* chunkBuffer, size_t chunkSize,
     230                                    media_encode_info* encodeInfo)
     231        {
     232            return fEncoder->WriteChunk(chunkBuffer, chunkSize, encodeInfo);
     233        }
     234    }* writer = new(std::nothrow) MediaEncoderChunkWriter(this);
     235   
     236    if (!writer)
     237        return B_NO_MEMORY;
     238   
     239    fEncoder->SetChunkWriter(writer);
     240    return B_OK;
     241}
     242
     243
    143244status_t BMediaEncoder::_Reserved_BMediaEncoder_0(int32 arg, ...) { return B_ERROR; }
    144245status_t BMediaEncoder::_Reserved_BMediaEncoder_1(int32 arg, ...) { return B_ERROR; }
    145246status_t BMediaEncoder::_Reserved_BMediaEncoder_2(int32 arg, ...) { return B_ERROR; }
    status_t BMediaEncoder::_Reserved_BMediaEncoder_15(int32 arg, ...) { return B_ER  
    162263 *************************************************************/
    163264
    164265BMediaBufferEncoder::BMediaBufferEncoder()
     266    :   BMediaEncoder(),
     267        fBuffer(NULL)
    165268{
    166     UNIMPLEMENTED();
     269
    167270}
    168271
    169272
    170273BMediaBufferEncoder::BMediaBufferEncoder(const media_format *output_format)
     274    :   BMediaEncoder(output_format),
     275        fBuffer(NULL)
    171276{
    172     UNIMPLEMENTED();
     277
    173278}
    174279
    175280
    176281BMediaBufferEncoder::BMediaBufferEncoder(const media_codec_info *mci)
     282    :   BMediaEncoder(mci),
     283        fBuffer(NULL)
    177284{
    178     UNIMPLEMENTED();
     285
    179286}
    180287
    181288
    BMediaBufferEncoder::EncodeToBuffer(void *output_buffer,  
    186293                                    int64 frame_count,
    187294                                    media_encode_info *info)
    188295{
    189     UNIMPLEMENTED();
    190 
    191     return B_ERROR;
     296    status_t error;
     297    fBuffer = output_buffer;
     298    fBufferSize = *output_size;
     299    error = Encode(input_buffer, frame_count, info);
     300    if (fBuffer) {
     301        fBuffer = NULL;
     302        *output_size = 0;
     303    } else {
     304        *output_size = fBufferSize;
     305    }
     306    return error;
    192307}
    193308
    194309
    BMediaBufferEncoder::WriteChunk(const void *chunk_data,  
    201316                                size_t chunk_len,
    202317                                media_encode_info *info)
    203318{
    204     UNIMPLEMENTED();
    205 
    206     return B_ERROR;
     319    if (fBuffer == NULL)
     320        return B_ENTRY_NOT_FOUND;
     321   
     322    if ((ssize_t)chunk_len < 0)
     323        return B_ERROR;
     324   
     325    if (chunk_len > (size_t)fBufferSize) {
     326        memcpy(fBuffer, chunk_data, fBufferSize);
     327        fBuffer = NULL;
     328        return B_DEVICE_FULL;
     329    }
     330   
     331    memcpy(fBuffer, chunk_data, chunk_len);
     332    fBufferSize = chunk_len;
     333    fBuffer = NULL;
     334    return B_NO_ERROR;
    207335}
    208 
    209 
  • src/kits/media/PluginManager.cpp

    diff --git a/src/kits/media/PluginManager.cpp b/src/kits/media/PluginManager.cpp
    index ffb816d..5dea9a0 100644
    a b  
    11/*
    22 * Copyright 2004-2010, Marcus Overhagen. All rights reserved.
    3  * Distributed under the terms of the OpenBeOS License.
     3 * Copyright 2012, Fredrik Modéen, [firstname]@[lastname].se.
     4 * Distributed under the terms of the MIT License.
    45 */
    56
    67#include <Path.h>
    PluginManager::CreateReader(Reader** reader, int32* streamCount,  
    2627
    2728    BPositionIO *seekable_source = dynamic_cast<BPositionIO *>(source);
    2829    if (seekable_source == 0) {
    29         printf("PluginManager::CreateReader: non-seekable sources not "
     30        ERROR("PluginManager::CreateReader: non-seekable sources not "
    3031            "supported yet\n");
    3132        return B_ERROR;
    3233    }
    PluginManager::CreateReader(Reader** reader, int32* streamCount,  
    3738    status_t ret = QueryServer(SERVER_GET_READERS, &request, sizeof(request),
    3839        &reply, sizeof(reply));
    3940    if (ret != B_OK) {
    40         printf("PluginManager::CreateReader: can't get list of readers: %s\n",
     41        ERROR("PluginManager::CreateReader: can't get list of readers: %s\n",
    4142            strerror(ret));
    4243        return ret;
    4344    }
    PluginManager::CreateReader(Reader** reader, int32* streamCount,  
    4748        entry_ref ref = reply.ref[i];
    4849        MediaPlugin* plugin = GetPlugin(ref);
    4950        if (plugin == NULL) {
    50             printf("PluginManager::CreateReader: GetPlugin failed\n");
     51            ERROR("PluginManager::CreateReader: GetPlugin failed\n");
    5152            return B_ERROR;
    5253        }
    5354
    5455        ReaderPlugin* readerPlugin = dynamic_cast<ReaderPlugin*>(plugin);
    5556        if (readerPlugin == NULL) {
    56             printf("PluginManager::CreateReader: dynamic_cast failed\n");
     57            ERROR("PluginManager::CreateReader: dynamic_cast failed\n");
    5758            PutPlugin(plugin);
    5859            return B_ERROR;
    5960        }
    6061
    6162        *reader = readerPlugin->NewReader();
    6263        if (*reader == NULL) {
    63             printf("PluginManager::CreateReader: NewReader failed\n");
     64            ERROR("PluginManager::CreateReader: NewReader failed\n");
    6465            PutPlugin(plugin);
    6566            return B_ERROR;
    6667        }
    PluginManager::CreateDecoder(Decoder** _decoder, const media_format& format)  
    113114    status_t ret = QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request,
    114115        sizeof(request), &reply, sizeof(reply));
    115116    if (ret != B_OK) {
    116         printf("PluginManager::CreateDecoder: can't get decoder for format: "
     117        ERROR("PluginManager::CreateDecoder: can't get decoder for format: "
    117118            "%s\n", strerror(ret));
    118119        return ret;
    119120    }
    120121
    121122    MediaPlugin* plugin = GetPlugin(reply.ref);
    122123    if (plugin == NULL) {
    123         printf("PluginManager::CreateDecoder: GetPlugin failed\n");
     124        ERROR("PluginManager::CreateDecoder: GetPlugin failed\n");
    124125        return B_ERROR;
    125126    }
    126127   
    127128    DecoderPlugin* decoderPlugin = dynamic_cast<DecoderPlugin*>(plugin);
    128129    if (decoderPlugin == NULL) {
    129         printf("PluginManager::CreateDecoder: dynamic_cast failed\n");
     130        ERROR("PluginManager::CreateDecoder: dynamic_cast failed\n");
    130131        PutPlugin(plugin);
    131132        return B_ERROR;
    132133    }
    PluginManager::CreateDecoder(Decoder** _decoder, const media_format& format)  
    135136    // but this is not yet handled (passing "0" as index/ID).
    136137    *_decoder = decoderPlugin->NewDecoder(0);
    137138    if (*_decoder == NULL) {
    138         printf("PluginManager::CreateDecoder: NewDecoder() failed\n");
     139        ERROR("PluginManager::CreateDecoder: NewDecoder() failed\n");
    139140        PutPlugin(plugin);
    140141        return B_ERROR;
    141142    }
    PluginManager::CreateDecoder(Decoder** _decoder, const media_format& format)  
    151152status_t
    152153PluginManager::CreateDecoder(Decoder** decoder, const media_codec_info& mci)
    153154{
    154     // TODO
     155    TRACE("PluginManager::CreateDecoder enter\n");
     156
     157    // get decoder for this format from the server
     158    server_get_decoder_for_codec_info_request request;
     159    server_get_decoder_for_codec_info_reply reply;
     160    request.id = mci.id;
     161    status_t ret = QueryServer(SERVER_GET_DECODER_FOR_CODEC_INFO, &request,
     162        sizeof(request), &reply, sizeof(reply));
     163    if (ret != B_OK) {
     164        ERROR("PluginManager::CreateDecoder: can't get decoder for format: "
     165            "%s\n", strerror(ret));
     166        return ret;
     167    }
     168
     169    MediaPlugin* plugin = GetPlugin(reply.ref);
     170    if (plugin == NULL) {
     171        ERROR("PluginManager::CreateDecoder: GetPlugin failed\n");
     172        return B_ERROR;
     173    }
     174   
     175    DecoderPlugin* decoderPlugin = dynamic_cast<DecoderPlugin*>(plugin);
     176    if (decoderPlugin == NULL) {
     177        ERROR("PluginManager::CreateDecoder: dynamic_cast failed\n");
     178        PutPlugin(plugin);
     179        return B_ERROR;
     180    }
     181   
     182    // TODO: In theory, one DecoderPlugin could support multiple Decoders,
     183    // but this is not yet handled (passing "0" as index/ID).
     184    *decoder = decoderPlugin->NewDecoder(0);
     185    if (*decoder == NULL) {
     186        ERROR("PluginManager::CreateDecoder: NewDecoder() failed\n");
     187        PutPlugin(plugin);
     188        return B_ERROR;
     189    }
     190    TRACE("  created decoder: %p\n", *decoder);
     191    (*decoder)->fMediaPlugin = plugin;
     192
     193    TRACE("PluginManager::CreateDecoder leave\n");
     194
     195    return B_OK;
     196/*  // TODO
    155197    debugger("not implemented");
    156     return B_ERROR;
     198    return B_ERROR;*/
    157199}
    158200
    159201
    PluginManager::CreateWriter(Writer** writer, const media_file_format& mff,  
    203245    status_t ret = QueryServer(SERVER_GET_WRITER_FOR_FORMAT_FAMILY, &request,
    204246        sizeof(request), &reply, sizeof(reply));
    205247    if (ret != B_OK) {
    206         printf("PluginManager::CreateWriter: can't get writer for file "
     248        ERROR("PluginManager::CreateWriter: can't get writer for file "
    207249            "family: %s\n", strerror(ret));
    208250        return ret;
    209251    }
    210252
    211253    MediaPlugin* plugin = GetPlugin(reply.ref);
    212254    if (plugin == NULL) {
    213         printf("PluginManager::CreateWriter: GetPlugin failed\n");
     255        ERROR("PluginManager::CreateWriter: GetPlugin failed\n");
    214256        return B_ERROR;
    215257    }
    216258
    217259    WriterPlugin* writerPlugin = dynamic_cast<WriterPlugin*>(plugin);
    218260    if (writerPlugin == NULL) {
    219         printf("PluginManager::CreateWriter: dynamic_cast failed\n");
     261        ERROR("PluginManager::CreateWriter: dynamic_cast failed\n");
    220262        PutPlugin(plugin);
    221263        return B_ERROR;
    222264    }
    223265
    224266    *writer = writerPlugin->NewWriter();
    225267    if (*writer == NULL) {
    226         printf("PluginManager::CreateWriter: NewWriter failed\n");
     268        ERROR("PluginManager::CreateWriter: NewWriter failed\n");
    227269        PutPlugin(plugin);
    228270        return B_ERROR;
    229271    }
    PluginManager::DestroyWriter(Writer* writer)  
    253295
    254296
    255297status_t
    256 PluginManager::CreateEncoder(Encoder** _encoder,
     298PluginManager::CreateEncoder(Encoder** encoder,
    257299    const media_codec_info* codecInfo, uint32 flags)
    258300{
    259301    TRACE("PluginManager::CreateEncoder enter\n");
    PluginManager::CreateEncoder(Encoder** _encoder,  
    265307    status_t ret = QueryServer(SERVER_GET_ENCODER_FOR_CODEC_INFO, &request,
    266308        sizeof(request), &reply, sizeof(reply));
    267309    if (ret != B_OK) {
    268         printf("PluginManager::CreateEncoder: can't get encoder for codec %s: "
     310        ERROR("PluginManager::CreateEncoder: can't get encoder for codec %s: "
    269311            "%s\n", codecInfo->pretty_name, strerror(ret));
    270312        return ret;
    271313    }
    272314
    273315    MediaPlugin* plugin = GetPlugin(reply.ref);
    274316    if (!plugin) {
    275         printf("PluginManager::CreateEncoder: GetPlugin failed\n");
     317        ERROR("PluginManager::CreateEncoder: GetPlugin failed\n");
    276318        return B_ERROR;
    277319    }
    278320   
    279321    EncoderPlugin* encoderPlugin = dynamic_cast<EncoderPlugin*>(plugin);
    280322    if (encoderPlugin == NULL) {
    281         printf("PluginManager::CreateEncoder: dynamic_cast failed\n");
     323        ERROR("PluginManager::CreateEncoder: dynamic_cast failed\n");
    282324        PutPlugin(plugin);
    283325        return B_ERROR;
    284326    }
    285327
    286     *_encoder = encoderPlugin->NewEncoder(*codecInfo);
    287     if (*_encoder == NULL) {
    288         printf("PluginManager::CreateEncoder: NewEncoder() failed\n");
     328    *encoder = encoderPlugin->NewEncoder(*codecInfo);
     329    if (*encoder == NULL) {
     330        ERROR("PluginManager::CreateEncoder: NewEncoder() failed\n");
    289331        PutPlugin(plugin);
    290332        return B_ERROR;
    291333    }
    292     TRACE("  created encoder: %p\n", *_encoder);
    293     (*_encoder)->fMediaPlugin = plugin;
     334    TRACE("  created encoder: %p\n", *encoder);
     335    (*encoder)->fMediaPlugin = plugin;
    294336
    295337    TRACE("PluginManager::CreateEncoder leave\n");
    296338
    PluginManager::CreateEncoder(Encoder** _encoder,  
    298340}
    299341
    300342
     343status_t
     344PluginManager::CreateEncoder(Encoder** encoder, const media_format& format)
     345{
     346    TRACE("PluginManager::CreateEncoder enter nr2\n");
     347    // Get encoder for this codec info from the server
     348    server_get_encoder_for_format_request request;
     349    server_get_encoder_for_format_reply reply;
     350    request.format = format;
     351    status_t ret = QueryServer(SERVER_GET_ENCODER_FOR_FORMAT, &request,
     352        sizeof(request), &reply, sizeof(reply));
     353    if (ret != B_OK) {
     354        ERROR("PluginManager::CreateEncoder: can't get decoder for format: "
     355            "%s\n", strerror(ret));
     356        return ret;
     357    }
     358
     359    MediaPlugin* plugin = GetPlugin(reply.ref);
     360    if (plugin == NULL) {
     361        ERROR("PluginManager::CreateEncoder: GetPlugin failed\n");
     362        return B_ERROR;
     363    }
     364   
     365    EncoderPlugin* encoderPlugin = dynamic_cast<EncoderPlugin*>(plugin);
     366    if (encoderPlugin == NULL) {
     367        ERROR("PluginManager::CreateEncoder: dynamic_cast failed\n");
     368        PutPlugin(plugin);
     369        return B_ERROR;
     370    }
     371
     372   
     373    *encoder = encoderPlugin->NewEncoder(format);
     374    if (*encoder == NULL) {
     375        ERROR("PluginManager::CreateEncoder: NewEncoder() failed\n");
     376        PutPlugin(plugin);
     377        return B_ERROR;
     378    }
     379    TRACE("  created encoder: %p\n", *encoder);
     380    (*encoder)->fMediaPlugin = plugin;
     381   
     382    TRACE("PluginManager::CreateEncoder leave nr2\n");
     383
     384    return B_OK;
     385}
     386
     387
    301388void
    302389PluginManager::DestroyEncoder(Encoder* encoder)
    303390{
    PluginManager::~PluginManager()  
    332419    for (int i = fPluginList.CountItems() - 1; i >= 0; i--) {
    333420        plugin_info* info = NULL;
    334421        fPluginList.Get(i, &info);
    335         printf("PluginManager: Error, unloading PlugIn %s with usecount "
     422        ERROR("PluginManager: Error, unloading PlugIn %s with usecount "
    336423            "%d\n", info->name, info->usecount);
    337424        delete info->plugin;
    338425        unload_add_on(info->image);
    PluginManager::GetPlugin(const entry_ref& ref)  
    361448    }
    362449
    363450    if (_LoadPlugin(ref, &info.plugin, &info.image) < B_OK) {
    364         printf("PluginManager: Error, loading PlugIn %s failed\n", ref.name);
     451        ERROR("PluginManager: Error, loading PlugIn %s failed\n", ref.name);
    365452        fLocker.Unlock();
    366453        return NULL;
    367454    }
    PluginManager::PutPlugin(MediaPlugin* plugin)  
    403490        }
    404491    }
    405492   
    406     printf("PluginManager: Error, can't put PlugIn %p\n", plugin);
     493    ERROR("PluginManager: Error, can't put PlugIn %p\n", plugin);
    407494   
    408495    fLocker.Unlock();
    409496}
    PluginManager::_LoadPlugin(const entry_ref& ref, MediaPlugin** plugin,  
    420507    image_id id;
    421508    id = load_add_on(p.Path());
    422509    if (id < 0) {
    423         printf("PluginManager: Error, load_add_on(): %s\n", strerror(id));
     510        ERROR("PluginManager: Error, load_add_on(): %s\n", strerror(id));
    424511        return B_ERROR;
    425512    }
    426513       
    PluginManager::_LoadPlugin(const entry_ref& ref, MediaPlugin** plugin,  
    428515   
    429516    if (get_image_symbol(id, "instantiate_plugin", B_SYMBOL_TYPE_TEXT,
    430517            (void**)&instantiate_plugin_func) < B_OK) {
    431         printf("PluginManager: Error, _LoadPlugin can't find "
     518        ERROR("PluginManager: Error, _LoadPlugin can't find "
    432519            "instantiate_plugin in %s\n", p.Path());
    433520        unload_add_on(id);
    434521        return B_ERROR;
    PluginManager::_LoadPlugin(const entry_ref& ref, MediaPlugin** plugin,  
    438525   
    439526    pl = (*instantiate_plugin_func)();
    440527    if (pl == NULL) {
    441         printf("PluginManager: Error, _LoadPlugin instantiate_plugin in %s "
     528        ERROR("PluginManager: Error, _LoadPlugin instantiate_plugin in %s "
    442529            "returned NULL\n", p.Path());
    443530        unload_add_on(id);
    444531        return B_ERROR;
  • src/servers/media/media_server.cpp

    diff --git a/src/servers/media/media_server.cpp b/src/servers/media/media_server.cpp
    index fd51cf77..80dbaab 100644
    a b ServerApp::_HandleMessage(int32 code, const void* data, size_t size)  
    896896            request.SendReply(status, &reply, sizeof(reply));
    897897            break;
    898898        }
     899       
     900        case SERVER_GET_DECODER_FOR_CODEC_INFO:
     901        {
     902            const server_get_decoder_for_codec_info_request& request
     903                = *static_cast<
     904                    const server_get_decoder_for_codec_info_request*>(data);
     905            server_get_decoder_for_codec_info_reply reply;
     906           
     907            status_t status = gAddOnManager->GetEncoder(&reply.ref, request.id);
     908            request.SendReply(status, &reply, sizeof(reply));
     909            break;
     910        }
    899911
    900912        case SERVER_GET_DECODER_FOR_FORMAT:
    901913        {
    ServerApp::_HandleMessage(int32 code, const void* data, size_t size)  
    946958            request.SendReply(status, &reply, sizeof(reply));
    947959            break;
    948960        }
     961       
     962        case SERVER_GET_ENCODER_FOR_FORMAT:
     963        {
     964            const server_get_encoder_for_format_request& request
     965                = *static_cast<
     966                    const server_get_encoder_for_format_request*>(data);
     967            server_get_encoder_for_format_reply reply;
     968
     969            status_t status = gAddOnManager->GetDecoderForFormat(&reply.ref,
     970                request.format);
     971            request.SendReply(status, &reply, sizeof(reply));
     972            break;
     973        }
    949974
    950975        case SERVER_GET_ENCODER_FOR_CODEC_INFO:
    951976        {
    ServerApp::_HandleMessage(int32 code, const void* data, size_t size)  
    953978                = *static_cast<
    954979                    const server_get_encoder_for_codec_info_request*>(data);
    955980            server_get_encoder_for_codec_info_reply reply;
     981           
    956982            status_t status = gAddOnManager->GetEncoder(&reply.ref, request.id);
    957983            request.SendReply(status, &reply, sizeof(reply));
    958984            break;