LCOV - code coverage report
Current view: top level - ext/musepack - gstmusepackreader.c (source / functions) Hit Total Coverage
Test: GStreamer Bad Plug-ins 0.10.21.1 Lines: 0 48 0.0 %
Date: 2011-03-25 Functions: 0 7 0.0 %
Branches: 0 24 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* GStreamer Musepack decoder plugin
       2                 :            :  * Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
       3                 :            :  *
       4                 :            :  * This library is free software; you can redistribute it and/or
       5                 :            :  * modify it under the terms of the GNU Library General Public
       6                 :            :  * License as published by the Free Software Foundation; either
       7                 :            :  * version 2 of the License, or (at your option) any later version.
       8                 :            :  *
       9                 :            :  * This library is distributed in the hope that it will be useful,
      10                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12                 :            :  * Library General Public License for more details.
      13                 :            :  *
      14                 :            :  * You should have received a copy of the GNU Library General Public
      15                 :            :  * License along with this library; if not, write to the
      16                 :            :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17                 :            :  * Boston, MA 02111-1307, USA.
      18                 :            :  */
      19                 :            : 
      20                 :            : #ifdef HAVE_CONFIG_H
      21                 :            : #include "config.h"
      22                 :            : #endif
      23                 :            : 
      24                 :            : #include "gstmusepackreader.h"
      25                 :            : #include <gst/gst.h>
      26                 :            : #include <string.h>
      27                 :            : 
      28                 :            : 
      29                 :            : GST_DEBUG_CATEGORY_EXTERN (musepackdec_debug);
      30                 :            : #define GST_CAT_DEFAULT musepackdec_debug
      31                 :            : 
      32                 :            : #ifdef MPC_IS_OLD_API
      33                 :            : static mpc_int32_t gst_musepack_reader_peek (void *this, void *ptr,
      34                 :            :     mpc_int32_t size);
      35                 :            : static mpc_int32_t gst_musepack_reader_read (void *this, void *ptr,
      36                 :            :     mpc_int32_t size);
      37                 :            : static mpc_bool_t gst_musepack_reader_seek (void *this, mpc_int32_t offset);
      38                 :            : static mpc_int32_t gst_musepack_reader_tell (void *this);
      39                 :            : static mpc_int32_t gst_musepack_reader_get_size (void *this);
      40                 :            : static mpc_bool_t gst_musepack_reader_canseek (void *this);
      41                 :            : #else
      42                 :            : static mpc_int32_t gst_musepack_reader_peek (mpc_reader * this, void *ptr,
      43                 :            :     mpc_int32_t size);
      44                 :            : static mpc_int32_t gst_musepack_reader_read (mpc_reader * this, void *ptr,
      45                 :            :     mpc_int32_t size);
      46                 :            : static mpc_bool_t gst_musepack_reader_seek (mpc_reader * this,
      47                 :            :     mpc_int32_t offset);
      48                 :            : static mpc_int32_t gst_musepack_reader_tell (mpc_reader * this);
      49                 :            : static mpc_int32_t gst_musepack_reader_get_size (mpc_reader * this);
      50                 :            : static mpc_bool_t gst_musepack_reader_canseek (mpc_reader * this);
      51                 :            : #endif
      52                 :            : 
      53                 :            : #ifdef MPC_IS_OLD_API
      54                 :            : static mpc_int32_t
      55                 :            : gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size)
      56                 :            : {
      57                 :            :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
      58                 :            : #else
      59                 :            : static mpc_int32_t
      60                 :          0 : gst_musepack_reader_peek (mpc_reader * this, void *ptr, mpc_int32_t size)
      61                 :            : {
      62                 :          0 :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data);
      63                 :            : #endif
      64                 :            :   GstFlowReturn flow_ret;
      65                 :          0 :   GstBuffer *buf = NULL;
      66                 :            :   guint read;
      67                 :            : 
      68         [ #  # ]:          0 :   g_return_val_if_fail (size > 0, 0);
      69                 :            : 
      70                 :            :   /* GST_LOG_OBJECT (musepackdec, "size=%d", size); */
      71                 :            : 
      72                 :          0 :   flow_ret = gst_pad_pull_range (musepackdec->sinkpad, musepackdec->offset,
      73                 :            :       size, &buf);
      74                 :            : 
      75         [ #  # ]:          0 :   if (flow_ret != GST_FLOW_OK) {
      76         [ #  # ]:          0 :     GST_DEBUG_OBJECT (musepackdec, "Flow: %s", gst_flow_get_name (flow_ret));
      77                 :          0 :     return 0;
      78                 :            :   }
      79                 :            : 
      80                 :          0 :   read = MIN (GST_BUFFER_SIZE (buf), size);
      81                 :            : 
      82         [ #  # ]:          0 :   if (read < size) {
      83         [ #  # ]:          0 :     GST_WARNING_OBJECT (musepackdec, "Short read: got only %u bytes of %u "
      84                 :            :         "bytes requested at offset %" G_GINT64_FORMAT, read, size,
      85                 :            :         musepackdec->offset);
      86                 :            :     /* GST_ELEMENT_ERROR (musepackdec, RESOURCE, READ, (NULL), (NULL)); */
      87                 :            :   }
      88                 :            : 
      89                 :          0 :   memcpy (ptr, GST_BUFFER_DATA (buf), read);
      90                 :          0 :   gst_buffer_unref (buf);
      91                 :          0 :   return read;
      92                 :            : }
      93                 :            : 
      94                 :            : #ifdef MPC_IS_OLD_API
      95                 :            : static mpc_int32_t
      96                 :            : gst_musepack_reader_read (void *this, void *ptr, mpc_int32_t size)
      97                 :            : {
      98                 :            :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
      99                 :            : #else
     100                 :            : static mpc_int32_t
     101                 :          0 : gst_musepack_reader_read (mpc_reader * this, void *ptr, mpc_int32_t size)
     102                 :            : {
     103                 :          0 :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data);
     104                 :            : #endif
     105                 :            :   gint read;
     106                 :            : 
     107                 :            :   /* read = peek + flush */
     108         [ #  # ]:          0 :   if ((read = gst_musepack_reader_peek (this, ptr, size)) > 0) {
     109                 :          0 :     musepackdec->offset += read;
     110                 :            :   }
     111                 :            : 
     112                 :          0 :   return read;
     113                 :            : }
     114                 :            : 
     115                 :            : #ifdef MPC_IS_OLD_API
     116                 :            : static mpc_bool_t
     117                 :            : gst_musepack_reader_seek (void *this, mpc_int32_t offset)
     118                 :            : {
     119                 :            :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
     120                 :            : #else
     121                 :            : static mpc_bool_t
     122                 :          0 : gst_musepack_reader_seek (mpc_reader * this, mpc_int32_t offset)
     123                 :            : {
     124                 :          0 :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data);
     125                 :            : #endif
     126                 :            :   mpc_int32_t length;
     127                 :            : 
     128                 :          0 :   length = gst_musepack_reader_get_size (this);
     129 [ #  # ][ #  # ]:          0 :   if (length > 0 && offset >= 0 && offset < length) {
                 [ #  # ]
     130                 :          0 :     musepackdec->offset = offset;
     131         [ #  # ]:          0 :     GST_LOG_OBJECT (musepackdec, "Seek'ed to byte offset %d", (gint) offset);
     132                 :          0 :     return TRUE;
     133                 :            :   } else {
     134         [ #  # ]:          0 :     GST_DEBUG_OBJECT (musepackdec, "Cannot seek to offset %d", (gint) offset);
     135                 :          0 :     return FALSE;
     136                 :            :   }
     137                 :            : }
     138                 :            : 
     139                 :            : #ifdef MPC_IS_OLD_API
     140                 :            : static mpc_int32_t
     141                 :            : gst_musepack_reader_tell (void *this)
     142                 :            : {
     143                 :            :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
     144                 :            : #else
     145                 :            : static mpc_int32_t
     146                 :          0 : gst_musepack_reader_tell (mpc_reader * this)
     147                 :            : {
     148                 :          0 :   GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data);
     149                 :            : #endif
     150                 :          0 :   return musepackdec->offset;
     151                 :            : }
     152                 :            : 
     153                 :            : #ifdef MPC_IS_OLD_API
     154                 :            : static mpc_int32_t
     155                 :            : gst_musepack_reader_get_size (void *this)
     156                 :            : {
     157                 :            :   GstMusepackDec *dec = GST_MUSEPACK_DEC (this);
     158                 :            : #else
     159                 :            : static mpc_int32_t
     160                 :          0 : gst_musepack_reader_get_size (mpc_reader * this)
     161                 :            : {
     162                 :          0 :   GstMusepackDec *dec = GST_MUSEPACK_DEC (this->data);
     163                 :            : #endif
     164                 :          0 :   GstFormat format = GST_FORMAT_BYTES;
     165                 :          0 :   gint64 length = -1;
     166                 :            : 
     167         [ #  # ]:          0 :   if (!gst_pad_query_peer_duration (dec->sinkpad, &format, &length))
     168                 :          0 :     length = -1;
     169                 :            : 
     170                 :          0 :   return (mpc_int32_t) length;
     171                 :            : }
     172                 :            : 
     173                 :            : #ifdef MPC_IS_OLD_API
     174                 :            : static mpc_bool_t
     175                 :            : gst_musepack_reader_canseek (void *this)
     176                 :            : #else
     177                 :            : static mpc_bool_t
     178                 :          0 : gst_musepack_reader_canseek (mpc_reader * this)
     179                 :            : #endif
     180                 :            : {
     181                 :          0 :   return TRUE;
     182                 :            : }
     183                 :            : 
     184                 :            : void
     185                 :          0 : gst_musepack_init_reader (mpc_reader * r, GstMusepackDec * musepackdec)
     186                 :            : {
     187                 :          0 :   r->data = musepackdec;
     188                 :            : 
     189                 :          0 :   r->read = gst_musepack_reader_read;
     190                 :          0 :   r->seek = gst_musepack_reader_seek;
     191                 :          0 :   r->tell = gst_musepack_reader_tell;
     192                 :          0 :   r->get_size = gst_musepack_reader_get_size;
     193                 :          0 :   r->canseek = gst_musepack_reader_canseek;
     194                 :          0 : }

Generated by: LCOV version 1.9