Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 9e1800c in mainline


Ignore:
Timestamp:
2013-03-17T16:23:57Z (7 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
master
Children:
bd5860f
Parents:
504f1ea3
Message:

libhound: Implement hound client side API sing client side protocol headers

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/wavplay/main.c

    r504f1ea3 r9e1800c  
    6060                return EIO;
    6161        }
    62         unsigned rate, channels;
    63         pcm_sample_format_t format;
     62        pcm_format_t format;
    6463        const char *error;
    65         int ret = wav_parse_header(&header, NULL, NULL, &channels, &rate,
    66             &format, &error);
     64        int ret = wav_parse_header(&header, NULL, NULL, &format.channels,
     65            &format.sampling_rate, &format.sample_format, &error);
    6766        if (ret != EOK) {
    6867                printf("Error parsing wav header: %s.\n", error);
     
    7170        }
    7271        hound_context_t *hound = hound_context_create_playback(filename,
    73             channels, rate, format, 0);
     72            format, 0);
    7473        if (!hound) {
    7574                printf("Failed to create HOUND context\n");
  • uspace/lib/hound/include/hound/client.h

    r504f1ea3 r9e1800c  
    3939#include <async.h>
    4040#include <stdbool.h>
    41 #include <pcm/sample_format.h>
     41#include <pcm/format.h>
    4242
    4343#define DEFAULT_SINK "default"
     
    4848
    4949hound_context_t * hound_context_create_playback(const char *name,
    50     unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize);
     50    pcm_format_t format, size_t bsize);
    5151hound_context_t * hound_context_create_capture(const char *name,
    52     unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize);
     52    pcm_format_t format, size_t bsize);
    5353void hound_context_destroy(hound_context_t *hound);
    5454
     
    6464int hound_context_disconnect_target(hound_context_t *hound, const char* target);
    6565
     66hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags,
     67    pcm_format_t format, size_t bsize);
     68void hound_stream_destroy(hound_stream_t *stream);
     69
     70int hound_stream_write(hound_stream_t *stream, const void *data, size_t size);
     71int hound_stream_read(hound_stream_t *stream, void *data, size_t size);
     72
    6673int hound_write_main_stream(hound_context_t *hound,
    6774    const void *data, size_t size);
     
    6976int hound_write_replace_main_stream(hound_context_t *hound,
    7077    const void *data, size_t size);
    71 int hound_write_immediate_stream(hound_context_t *hound,
    72     const void *data, size_t size);
    73 
    74 hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags,
    75     unsigned channels, unsigned rate, pcm_sample_format_t format);
    76 void hound_stream_destroy(hound_stream_t *stream);
    77 
    78 int hound_stream_write(hound_stream_t *stream, const void *data, size_t size);
    79 int hound_stream_read(hound_stream_t *stream, void *data, size_t size);
     78int hound_write_immediate(hound_context_t *hound,
     79    pcm_format_t format, const void *data, size_t size);
    8080
    8181
  • uspace/lib/hound/src/client.c

    r504f1ea3 r9e1800c  
    4242#include <libarch/types.h>
    4343
     44#include "protocol.h"
    4445#include "client.h"
    45 #include "protocol.h"
    4646
    4747/***
     
    5151typedef struct hound_stream {
    5252        link_t link;
     53        pcm_format_t format;
    5354        async_exch_t *exch;
     55        hound_context_t *context;
    5456} hound_stream_t;
    5557
     
    5961        bool record;
    6062        list_t stream_list;
    61         hound_stream_t *main_stream;
    6263        struct {
    63                 pcm_sample_format_t sample;
    64                 unsigned channels;
    65                 unsigned rate;
     64                hound_stream_t *stream;
     65                pcm_format_t format;
    6666                size_t bsize;
    67         } main_format;
    68         unsigned id;
     67        } main;
     68        hound_context_id_t id;
    6969} hound_context_t;
    7070
    7171
    7272static hound_context_t *hound_context_create(const char *name, bool record,
    73     unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
     73    pcm_format_t format, size_t bsize)
    7474{
    7575        hound_context_t *new_context = malloc(sizeof(hound_context_t));
     
    8585                new_context->record = record;
    8686                new_context->session = hound_service_connect(HOUND_SERVICE);
    87                 new_context->main_stream = NULL;
    88                 new_context->main_format.sample = format;
    89                 new_context->main_format.rate = rate;
    90                 new_context->main_format.channels = channels;
    91                 new_context->main_format.bsize = bsize;
     87                new_context->main.stream = NULL;
     88                new_context->main.format = format;
     89                new_context->main.bsize = bsize;
    9290                if (!new_context->session) {
    9391                        free(new_context->name);
     
    9593                        return NULL;
    9694                }
    97                 async_exch_t *exch = async_exchange_begin(new_context->session);
    98                 //TODO: register context
    99                 async_exchange_end(exch);
     95                new_context->id = hound_service_register_context(
     96                    new_context->session, new_context->name);
     97                if (new_context->id <= 0) {
     98                        free(new_context->name);
     99                        free(new_context);
     100                        return NULL;
     101                }
    100102        }
    101103        return new_context;
     
    103105
    104106hound_context_t * hound_context_create_playback(const char *name,
    105     unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
    106 {
    107         return hound_context_create(name, false, channels, rate, format, bsize);
     107    pcm_format_t format, size_t bsize)
     108{
     109        return hound_context_create(name, false, format, bsize);
    108110}
    109111
    110112hound_context_t * hound_context_create_capture(const char *name,
    111     unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
    112 {
    113         return hound_context_create(name, true, channels, rate, format, bsize);
     113    pcm_format_t format, size_t bsize)
     114{
     115        return hound_context_create(name, true, format, bsize);
    114116}
    115117
     
    117119{
    118120        assert(hound);
     121        hound_service_unregister_context(hound->session, hound->id);
     122        hound_service_disconnect(hound->session);
     123        free(hound->name);
     124        free(hound);
    119125}
    120126
     
    156162}
    157163
     164hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags,
     165    pcm_format_t format, size_t bsize)
     166{
     167        assert(hound);
     168        async_exch_t *stream_exch = async_exchange_begin(hound->session);
     169        if (!stream_exch)
     170                return NULL;
     171        hound_stream_t *new_stream = malloc(sizeof(hound_stream_t));
     172        if (new_stream) {
     173                link_initialize(&new_stream->link);
     174                new_stream->exch = stream_exch;
     175                new_stream->format = format;
     176                new_stream->context = hound;
     177                int ret = hound_service_stream_enter(new_stream->exch,
     178                    hound->id, flags, format, bsize);
     179                if (ret != EOK) {
     180                        async_exchange_end(new_stream->exch);
     181                        free(new_stream);
     182                        return NULL;
     183                }
     184                list_append(&new_stream->link, &hound->stream_list);
     185        }
     186        return new_stream;
     187}
     188
     189void hound_stream_destroy(hound_stream_t *stream)
     190{
     191        if (stream) {
     192                // TODO drain?
     193                hound_service_stream_exit(stream->exch);
     194                async_exchange_end(stream->exch);
     195                list_remove(&stream->link);
     196                free(stream);
     197        }
     198}
     199
     200int hound_stream_write(hound_stream_t *stream, const void *data, size_t size)
     201{
     202        assert(stream);
     203        if (!data || size == 0)
     204                return EBADMEM;
     205        return hound_service_stream_write(stream->exch, data, size);
     206}
     207
     208int hound_stream_read(hound_stream_t *stream, void *data, size_t size)
     209{
     210        assert(stream);
     211        if (!data || size == 0)
     212                return EBADMEM;
     213        return hound_service_stream_read(stream->exch, data, size);
     214}
     215
     216static hound_stream_t * hound_get_main_stream(hound_context_t *hound)
     217{
     218        assert(hound);
     219        if (!hound->main.stream)
     220                hound->main.stream = hound_stream_create(hound, 0,
     221                    hound->main.format, hound->main.bsize);
     222        return hound->main.stream;
     223}
     224
     225int hound_write_main_stream(hound_context_t *hound,
     226    const void *data, size_t size)
     227{
     228        assert(hound);
     229        hound_stream_t *mstream = hound_get_main_stream(hound);
     230        if (!mstream)
     231                return ENOMEM;
     232        return hound_stream_write(mstream, data, size);
     233}
     234
     235int hound_read_main_stream(hound_context_t *hound, void *data, size_t size)
     236{
     237        assert(hound);
     238        hound_stream_t *mstream = hound_get_main_stream(hound);
     239        if (!mstream)
     240                return ENOMEM;
     241        return hound_stream_read(mstream, data, size);
     242}
     243
     244int hound_write_replace_main_stream(hound_context_t *hound,
     245    const void *data, size_t size)
     246{
     247        assert(hound);
     248        if (!data || size == 0)
     249                return EBADMEM;
     250        // TODO implement
     251        return ENOTSUP;
     252}
     253
    158254int hound_context_set_main_stream_format(hound_context_t *hound,
    159     unsigned channels, unsigned rate, pcm_sample_format_t format);
    160 int hound_write_main_stream(hound_context_t *hound,
    161     const void *data, size_t size);
    162 int hound_read_main_stream(hound_context_t *hound, void *data, size_t size);
    163 int hound_write_replace_main_stream(hound_context_t *hound,
    164     const void *data, size_t size);
    165 int hound_write_immediate_stream(hound_context_t *hound,
    166     const void *data, size_t size);
     255    unsigned channels, unsigned rate, pcm_sample_format_t format)
     256{
     257        assert(hound);
     258        // TODO implement
     259        return ENOTSUP;
     260}
     261
     262int hound_write_immediate(hound_context_t *hound, pcm_format_t format,
     263    const void *data, size_t size)
     264{
     265        assert(hound);
     266        hound_stream_t *tmpstream = hound_stream_create(hound, 0, format, size);
     267        if (!tmpstream)
     268                return ENOMEM;
     269        const int ret = hound_stream_write(tmpstream, data, size);
     270        if (ret == EOK) {
     271                //TODO drain?
     272                hound_service_stream_drain(tmpstream->exch);
     273        }
     274        hound_stream_destroy(tmpstream);
     275        return ret;
     276}
     277
    167278
    168279/**
Note: See TracChangeset for help on using the changeset viewer.