LCOV - code coverage report
Current view: top level - ext/wavpack - gstwavpackstreamreader.c (source / functions) Hit Total Coverage
Test: GStreamer Good Plug-ins 0.10.28.1 Lines: 35 45 77.8 %
Date: 2011-03-25 Functions: 6 9 66.7 %
Branches: 6 20 30.0 %

           Branch data     Line data    Source code
       1                 :            : /* GStreamer Wavpack plugin
       2                 :            :  * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
       3                 :            :  *
       4                 :            :  * gstwavpackstreamreader.c: stream reader used for decoding
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Library General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Library General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Library General Public
      17                 :            :  * License along with this library; if not, write to the
      18                 :            :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      19                 :            :  * Boston, MA 02111-1307, USA.
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <string.h>
      23                 :            : #include <math.h>
      24                 :            : #include <gst/gst.h>
      25                 :            : 
      26                 :            : #include "gstwavpackstreamreader.h"
      27                 :            : 
      28                 :            : GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
      29                 :            : #define GST_CAT_DEFAULT wavpack_debug
      30                 :            : 
      31                 :            : static int32_t
      32                 :        106 : gst_wavpack_stream_reader_read_bytes (void *id, void *data, int32_t bcount)
      33                 :            : {
      34                 :        106 :   read_id *rid = (read_id *) id;
      35                 :        106 :   uint32_t left = rid->length - rid->position;
      36                 :        106 :   uint32_t to_read = MIN (left, bcount);
      37                 :            : 
      38         [ -  + ]:        106 :   GST_DEBUG ("Trying to read %d of %d bytes from position %d", bcount,
      39                 :            :       rid->length, rid->position);
      40                 :            : 
      41         [ +  - ]:        106 :   if (to_read > 0) {
      42                 :        106 :     g_memmove (data, rid->buffer + rid->position, to_read);
      43                 :        106 :     rid->position += to_read;
      44                 :        106 :     return to_read;
      45                 :            :   } else {
      46         [ #  # ]:          0 :     GST_WARNING ("Couldn't read %d bytes", bcount);
      47                 :        106 :     return 0;
      48                 :            :   }
      49                 :            : }
      50                 :            : 
      51                 :            : static uint32_t
      52                 :         51 : gst_wavpack_stream_reader_get_pos (void *id)
      53                 :            : {
      54         [ -  + ]:         51 :   GST_DEBUG ("Returning position %d", ((read_id *) id)->position);
      55                 :         51 :   return ((read_id *) id)->position;
      56                 :            : }
      57                 :            : 
      58                 :            : static int
      59                 :          0 : gst_wavpack_stream_reader_set_pos_abs (void *id, uint32_t pos)
      60                 :            : {
      61         [ #  # ]:          0 :   GST_WARNING ("Should not be called: tried to set absolute position to %d",
      62                 :            :       pos);
      63                 :          0 :   return -1;
      64                 :            : }
      65                 :            : 
      66                 :            : static int
      67                 :          0 : gst_wavpack_stream_reader_set_pos_rel (void *id, int32_t delta, int mode)
      68                 :            : {
      69         [ #  # ]:          0 :   GST_WARNING ("Should not be called: tried to set relative position to %d"
      70                 :            :       " with mode %d", delta, mode);
      71                 :          0 :   return -1;
      72                 :            : }
      73                 :            : 
      74                 :            : static int
      75                 :          4 : gst_wavpack_stream_reader_push_back_byte (void *id, int c)
      76                 :            : {
      77                 :          4 :   read_id *rid = (read_id *) id;
      78                 :            : 
      79         [ -  + ]:          4 :   GST_DEBUG ("Pushing back one byte: 0x%x", c);
      80                 :            : 
      81                 :          4 :   rid->position -= 1;
      82                 :            :   if (rid->position < 0)
      83                 :            :     rid->position = 0;
      84                 :          4 :   return rid->position;
      85                 :            : }
      86                 :            : 
      87                 :            : static uint32_t
      88                 :          4 : gst_wavpack_stream_reader_get_length (void *id)
      89                 :            : {
      90         [ -  + ]:          4 :   GST_DEBUG ("Returning length %d", ((read_id *) id)->length);
      91                 :            : 
      92                 :          4 :   return ((read_id *) id)->length;
      93                 :            : }
      94                 :            : 
      95                 :            : static int
      96                 :          1 : gst_wavpack_stream_reader_can_seek (void *id)
      97                 :            : {
      98         [ -  + ]:          1 :   GST_DEBUG ("Can't seek");
      99                 :          1 :   return FALSE;
     100                 :            : }
     101                 :            : 
     102                 :            : static int32_t
     103                 :          0 : gst_wavpack_stream_reader_write_bytes (void *id, void *data, int32_t bcount)
     104                 :            : {
     105         [ #  # ]:          0 :   GST_WARNING ("Should not be called, tried to write %d bytes", bcount);
     106                 :          0 :   return 0;
     107                 :            : }
     108                 :            : 
     109                 :            : WavpackStreamReader *
     110                 :          9 : gst_wavpack_stream_reader_new (void)
     111                 :            : {
     112                 :          9 :   WavpackStreamReader *stream_reader =
     113                 :            :       (WavpackStreamReader *) g_malloc0 (sizeof (WavpackStreamReader));
     114                 :          9 :   stream_reader->read_bytes = gst_wavpack_stream_reader_read_bytes;
     115                 :          9 :   stream_reader->get_pos = gst_wavpack_stream_reader_get_pos;
     116                 :          9 :   stream_reader->set_pos_abs = gst_wavpack_stream_reader_set_pos_abs;
     117                 :          9 :   stream_reader->set_pos_rel = gst_wavpack_stream_reader_set_pos_rel;
     118                 :          9 :   stream_reader->push_back_byte = gst_wavpack_stream_reader_push_back_byte;
     119                 :          9 :   stream_reader->get_length = gst_wavpack_stream_reader_get_length;
     120                 :          9 :   stream_reader->can_seek = gst_wavpack_stream_reader_can_seek;
     121                 :          9 :   stream_reader->write_bytes = gst_wavpack_stream_reader_write_bytes;
     122                 :            : 
     123                 :          9 :   return stream_reader;
     124                 :            : }

Generated by: LCOV version 1.9