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