Blame ext/wavpack/gstwavpackstreamreader.c

Packit 8ff292
/* GStreamer Wavpack plugin
Packit 8ff292
 * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
Packit 8ff292
 *
Packit 8ff292
 * gstwavpackstreamreader.c: stream reader used for decoding
Packit 8ff292
 *
Packit 8ff292
 * This library is free software; you can redistribute it and/or
Packit 8ff292
 * modify it under the terms of the GNU Library General Public
Packit 8ff292
 * License as published by the Free Software Foundation; either
Packit 8ff292
 * version 2 of the License, or (at your option) any later version.
Packit 8ff292
 *
Packit 8ff292
 * This library is distributed in the hope that it will be useful,
Packit 8ff292
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8ff292
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 8ff292
 * Library General Public License for more details.
Packit 8ff292
 *
Packit 8ff292
 * You should have received a copy of the GNU Library General Public
Packit 8ff292
 * License along with this library; if not, write to the
Packit 8ff292
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 8ff292
 * Boston, MA 02110-1301, USA.
Packit 8ff292
 */
Packit 8ff292
Packit 8ff292
#include <string.h>
Packit 8ff292
#include <math.h>
Packit 8ff292
#include <gst/gst.h>
Packit 8ff292
Packit 8ff292
#include "gstwavpackstreamreader.h"
Packit 8ff292
Packit 8ff292
GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
Packit 8ff292
#define GST_CAT_DEFAULT wavpack_debug
Packit 8ff292
Packit 8ff292
static int32_t
Packit 8ff292
gst_wavpack_stream_reader_read_bytes (void *id, void *data, int32_t bcount)
Packit 8ff292
{
Packit 8ff292
  read_id *rid = (read_id *) id;
Packit 8ff292
  uint32_t left = rid->length - rid->position;
Packit 8ff292
  uint32_t to_read = MIN (left, bcount);
Packit 8ff292
Packit 8ff292
  GST_DEBUG ("Trying to read %d of %d bytes from position %d", bcount,
Packit 8ff292
      rid->length, rid->position);
Packit 8ff292
Packit 8ff292
  if (to_read > 0) {
Packit 8ff292
    memmove (data, rid->buffer + rid->position, to_read);
Packit 8ff292
    rid->position += to_read;
Packit 8ff292
    return to_read;
Packit 8ff292
  } else {
Packit 8ff292
    GST_WARNING ("Couldn't read %d bytes", bcount);
Packit 8ff292
    return 0;
Packit 8ff292
  }
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static uint32_t
Packit 8ff292
gst_wavpack_stream_reader_get_pos (void *id)
Packit 8ff292
{
Packit 8ff292
  GST_DEBUG ("Returning position %d", ((read_id *) id)->position);
Packit 8ff292
  return ((read_id *) id)->position;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static int
Packit 8ff292
gst_wavpack_stream_reader_set_pos_abs (void *id, uint32_t pos)
Packit 8ff292
{
Packit 8ff292
  GST_WARNING ("Should not be called: tried to set absolute position to %d",
Packit 8ff292
      pos);
Packit 8ff292
  return -1;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static int
Packit 8ff292
gst_wavpack_stream_reader_set_pos_rel (void *id, int32_t delta, int mode)
Packit 8ff292
{
Packit 8ff292
  GST_WARNING ("Should not be called: tried to set relative position to %d"
Packit 8ff292
      " with mode %d", delta, mode);
Packit 8ff292
  return -1;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static int
Packit 8ff292
gst_wavpack_stream_reader_push_back_byte (void *id, int c)
Packit 8ff292
{
Packit 8ff292
  read_id *rid = (read_id *) id;
Packit 8ff292
Packit 8ff292
  GST_DEBUG ("Pushing back one byte: 0x%x", c);
Packit 8ff292
Packit 8ff292
  if (rid->position == 0)
Packit 8ff292
    return rid->position;
Packit 8ff292
Packit 8ff292
  rid->position -= 1;
Packit 8ff292
  return rid->position;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static uint32_t
Packit 8ff292
gst_wavpack_stream_reader_get_length (void *id)
Packit 8ff292
{
Packit 8ff292
  GST_DEBUG ("Returning length %d", ((read_id *) id)->length);
Packit 8ff292
Packit 8ff292
  return ((read_id *) id)->length;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static int
Packit 8ff292
gst_wavpack_stream_reader_can_seek (void *id)
Packit 8ff292
{
Packit 8ff292
  GST_DEBUG ("Can't seek");
Packit 8ff292
  return FALSE;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
static int32_t
Packit 8ff292
gst_wavpack_stream_reader_write_bytes (void *id, void *data, int32_t bcount)
Packit 8ff292
{
Packit 8ff292
  GST_WARNING ("Should not be called, tried to write %d bytes", bcount);
Packit 8ff292
  return 0;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
WavpackStreamReader *
Packit 8ff292
gst_wavpack_stream_reader_new (void)
Packit 8ff292
{
Packit 8ff292
  WavpackStreamReader *stream_reader =
Packit 8ff292
      (WavpackStreamReader *) g_malloc0 (sizeof (WavpackStreamReader));
Packit 8ff292
  stream_reader->read_bytes = gst_wavpack_stream_reader_read_bytes;
Packit 8ff292
  stream_reader->get_pos = gst_wavpack_stream_reader_get_pos;
Packit 8ff292
  stream_reader->set_pos_abs = gst_wavpack_stream_reader_set_pos_abs;
Packit 8ff292
  stream_reader->set_pos_rel = gst_wavpack_stream_reader_set_pos_rel;
Packit 8ff292
  stream_reader->push_back_byte = gst_wavpack_stream_reader_push_back_byte;
Packit 8ff292
  stream_reader->get_length = gst_wavpack_stream_reader_get_length;
Packit 8ff292
  stream_reader->can_seek = gst_wavpack_stream_reader_can_seek;
Packit 8ff292
  stream_reader->write_bytes = gst_wavpack_stream_reader_write_bytes;
Packit 8ff292
Packit 8ff292
  return stream_reader;
Packit 8ff292
}