Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
fcc11bc9
Commit
fcc11bc9
authored
Nov 02, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
music_pipe: added functions chunk_init() and chunk_free()
These two functions will care about memory allocation and deallocation in the future.
parent
85b6ff7b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
10 deletions
+38
-10
pipe.c
src/pipe.c
+38
-10
No files found.
src/pipe.c
View file @
fcc11bc9
...
@@ -26,6 +26,18 @@
...
@@ -26,6 +26,18 @@
struct
music_pipe
music_pipe
;
struct
music_pipe
music_pipe
;
static
void
music_chunk_init
(
struct
music_chunk
*
chunk
)
{
chunk
->
length
=
0
;
}
static
void
music_chunk_free
(
struct
music_chunk
*
chunk
)
{
(
void
)
chunk
;
}
void
void
music_pipe_init
(
unsigned
int
size
,
struct
notify
*
notify
)
music_pipe_init
(
unsigned
int
size
,
struct
notify
*
notify
)
{
{
...
@@ -37,19 +49,16 @@ music_pipe_init(unsigned int size, struct notify *notify)
...
@@ -37,19 +49,16 @@ music_pipe_init(unsigned int size, struct notify *notify)
music_pipe
.
end
=
0
;
music_pipe
.
end
=
0
;
music_pipe
.
lazy
=
false
;
music_pipe
.
lazy
=
false
;
music_pipe
.
notify
=
notify
;
music_pipe
.
notify
=
notify
;
music_
pipe
.
chunks
[
0
].
length
=
0
;
music_
chunk_init
(
&
music_pipe
.
chunks
[
0
])
;
}
}
void
music_pipe_free
(
void
)
void
music_pipe_free
(
void
)
{
{
assert
(
music_pipe
.
chunks
!=
NULL
);
assert
(
music_pipe
.
chunks
!=
NULL
);
g_free
(
music_pipe
.
chunks
);
}
void
music_pipe_clear
(
void
)
music_pipe_clear
();
{
music_pipe
.
end
=
music_pipe
.
begin
;
g_free
(
music_pipe
.
chunks
);
music_pipe
.
chunks
[
music_pipe
.
end
].
length
=
0
;
}
}
/** return the index of the chunk after i */
/** return the index of the chunk after i */
...
@@ -61,6 +70,19 @@ static inline unsigned successor(unsigned i)
...
@@ -61,6 +70,19 @@ static inline unsigned successor(unsigned i)
return
i
==
music_pipe
.
num_chunks
?
0
:
i
;
return
i
==
music_pipe
.
num_chunks
?
0
:
i
;
}
}
void
music_pipe_clear
(
void
)
{
unsigned
i
;
for
(
i
=
music_pipe
.
begin
;
i
!=
music_pipe
.
end
;
i
=
successor
(
i
))
music_chunk_free
(
&
music_pipe
.
chunks
[
i
]);
music_chunk_free
(
&
music_pipe
.
chunks
[
music_pipe
.
end
]);
music_pipe
.
end
=
music_pipe
.
begin
;
music_chunk_init
(
&
music_pipe
.
chunks
[
music_pipe
.
end
]);
}
/**
/**
* Mark the tail chunk as "full" and wake up the player if is waiting
* Mark the tail chunk as "full" and wake up the player if is waiting
* for the decoder.
* for the decoder.
...
@@ -73,7 +95,8 @@ static void output_buffer_expand(unsigned i)
...
@@ -73,7 +95,8 @@ static void output_buffer_expand(unsigned i)
assert
(
i
!=
music_pipe
.
end
);
assert
(
i
!=
music_pipe
.
end
);
music_pipe
.
end
=
i
;
music_pipe
.
end
=
i
;
music_pipe
.
chunks
[
i
].
length
=
0
;
music_chunk_init
(
&
music_pipe
.
chunks
[
i
]);
if
(
was_empty
)
if
(
was_empty
)
/* if the buffer was empty, the player thread might be
/* if the buffer was empty, the player thread might be
waiting for us; wake it up now that another decoded
waiting for us; wake it up now that another decoded
...
@@ -107,6 +130,8 @@ void music_pipe_shift(void)
...
@@ -107,6 +130,8 @@ void music_pipe_shift(void)
assert
(
music_pipe
.
begin
!=
music_pipe
.
end
);
assert
(
music_pipe
.
begin
!=
music_pipe
.
end
);
assert
(
music_pipe
.
begin
<
music_pipe
.
num_chunks
);
assert
(
music_pipe
.
begin
<
music_pipe
.
num_chunks
);
music_chunk_free
(
&
music_pipe
.
chunks
[
music_pipe
.
begin
]);
music_pipe
.
begin
=
successor
(
music_pipe
.
begin
);
music_pipe
.
begin
=
successor
(
music_pipe
.
begin
);
}
}
...
@@ -241,6 +266,9 @@ size_t music_pipe_append(const void *data0, size_t datalen,
...
@@ -241,6 +266,9 @@ size_t music_pipe_append(const void *data0, size_t datalen,
void
music_pipe_skip
(
unsigned
num
)
void
music_pipe_skip
(
unsigned
num
)
{
{
int
i
=
music_pipe_absolute
(
num
);
int
i
=
music_pipe_absolute
(
num
);
if
(
i
>=
0
)
if
(
i
<
0
)
music_pipe
.
begin
=
i
;
return
;
while
(
music_pipe
.
begin
!=
(
unsigned
)
i
)
music_pipe_shift
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment