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
466c337b
Commit
466c337b
authored
Apr 05, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoder_plugin: add state assertions
parent
98a468a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
2 deletions
+61
-2
encoder_plugin.h
src/encoder_plugin.h
+61
-2
No files found.
src/encoder_plugin.h
View file @
466c337b
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include <glib.h>
#include <glib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdbool.h>
#include <stddef.h>
#include <stddef.h>
...
@@ -32,6 +33,10 @@ struct tag;
...
@@ -32,6 +33,10 @@ struct tag;
struct
encoder
{
struct
encoder
{
const
struct
encoder_plugin
*
plugin
;
const
struct
encoder_plugin
*
plugin
;
#ifndef NDEBUG
bool
open
,
pre_tag
,
tag
;
#endif
};
};
struct
encoder_plugin
{
struct
encoder_plugin
{
...
@@ -73,6 +78,10 @@ encoder_struct_init(struct encoder *encoder,
...
@@ -73,6 +78,10 @@ encoder_struct_init(struct encoder *encoder,
const
struct
encoder_plugin
*
plugin
)
const
struct
encoder_plugin
*
plugin
)
{
{
encoder
->
plugin
=
plugin
;
encoder
->
plugin
=
plugin
;
#ifndef NDEBUG
encoder
->
open
=
false
;
#endif
}
}
/**
/**
...
@@ -98,6 +107,8 @@ encoder_init(const struct encoder_plugin *plugin,
...
@@ -98,6 +107,8 @@ encoder_init(const struct encoder_plugin *plugin,
static
inline
void
static
inline
void
encoder_finish
(
struct
encoder
*
encoder
)
encoder_finish
(
struct
encoder
*
encoder
)
{
{
assert
(
!
encoder
->
open
);
encoder
->
plugin
->
finish
(
encoder
);
encoder
->
plugin
->
finish
(
encoder
);
}
}
...
@@ -116,7 +127,14 @@ static inline bool
...
@@ -116,7 +127,14 @@ static inline bool
encoder_open
(
struct
encoder
*
encoder
,
struct
audio_format
*
audio_format
,
encoder_open
(
struct
encoder
*
encoder
,
struct
audio_format
*
audio_format
,
GError
**
error
)
GError
**
error
)
{
{
return
encoder
->
plugin
->
open
(
encoder
,
audio_format
,
error
);
assert
(
!
encoder
->
open
);
bool
success
=
encoder
->
plugin
->
open
(
encoder
,
audio_format
,
error
);
#ifndef NDEBUG
encoder
->
open
=
success
;
encoder
->
pre_tag
=
encoder
->
tag
=
false
;
#endif
return
success
;
}
}
/**
/**
...
@@ -128,8 +146,14 @@ encoder_open(struct encoder *encoder, struct audio_format *audio_format,
...
@@ -128,8 +146,14 @@ encoder_open(struct encoder *encoder, struct audio_format *audio_format,
static
inline
void
static
inline
void
encoder_close
(
struct
encoder
*
encoder
)
encoder_close
(
struct
encoder
*
encoder
)
{
{
assert
(
encoder
->
open
);
if
(
encoder
->
plugin
->
close
!=
NULL
)
if
(
encoder
->
plugin
->
close
!=
NULL
)
encoder
->
plugin
->
close
(
encoder
);
encoder
->
plugin
->
close
(
encoder
);
#ifndef NDEBUG
encoder
->
open
=
false
;
#endif
}
}
/**
/**
...
@@ -143,6 +167,10 @@ encoder_close(struct encoder *encoder)
...
@@ -143,6 +167,10 @@ encoder_close(struct encoder *encoder)
static
inline
bool
static
inline
bool
encoder_flush
(
struct
encoder
*
encoder
,
GError
**
error
)
encoder_flush
(
struct
encoder
*
encoder
,
GError
**
error
)
{
{
assert
(
encoder
->
open
);
assert
(
!
encoder
->
pre_tag
);
assert
(
!
encoder
->
tag
);
/* this method is optional */
/* this method is optional */
return
encoder
->
plugin
->
flush
!=
NULL
return
encoder
->
plugin
->
flush
!=
NULL
?
encoder
->
plugin
->
flush
(
encoder
,
error
)
?
encoder
->
plugin
->
flush
(
encoder
,
error
)
...
@@ -162,10 +190,19 @@ encoder_flush(struct encoder *encoder, GError **error)
...
@@ -162,10 +190,19 @@ encoder_flush(struct encoder *encoder, GError **error)
static
inline
bool
static
inline
bool
encoder_pre_tag
(
struct
encoder
*
encoder
,
GError
**
error
)
encoder_pre_tag
(
struct
encoder
*
encoder
,
GError
**
error
)
{
{
assert
(
encoder
->
open
);
assert
(
!
encoder
->
pre_tag
);
assert
(
!
encoder
->
tag
);
/* this method is optional */
/* this method is optional */
return
encoder
->
plugin
->
pre_tag
!=
NULL
bool
success
=
encoder
->
plugin
->
pre_tag
!=
NULL
?
encoder
->
plugin
->
pre_tag
(
encoder
,
error
)
?
encoder
->
plugin
->
pre_tag
(
encoder
,
error
)
:
true
;
:
true
;
#ifndef NDEBUG
encoder
->
pre_tag
=
success
;
#endif
return
success
;
}
}
/**
/**
...
@@ -182,6 +219,14 @@ encoder_pre_tag(struct encoder *encoder, GError **error)
...
@@ -182,6 +219,14 @@ encoder_pre_tag(struct encoder *encoder, GError **error)
static
inline
bool
static
inline
bool
encoder_tag
(
struct
encoder
*
encoder
,
const
struct
tag
*
tag
,
GError
**
error
)
encoder_tag
(
struct
encoder
*
encoder
,
const
struct
tag
*
tag
,
GError
**
error
)
{
{
assert
(
encoder
->
open
);
assert
(
!
encoder
->
pre_tag
);
assert
(
encoder
->
tag
);
#ifndef NDEBUG
encoder
->
tag
=
false
;
#endif
/* this method is optional */
/* this method is optional */
return
encoder
->
plugin
->
tag
!=
NULL
return
encoder
->
plugin
->
tag
!=
NULL
?
encoder
->
plugin
->
tag
(
encoder
,
tag
,
error
)
?
encoder
->
plugin
->
tag
(
encoder
,
tag
,
error
)
...
@@ -201,6 +246,10 @@ static inline bool
...
@@ -201,6 +246,10 @@ static inline bool
encoder_write
(
struct
encoder
*
encoder
,
const
void
*
data
,
size_t
length
,
encoder_write
(
struct
encoder
*
encoder
,
const
void
*
data
,
size_t
length
,
GError
**
error
)
GError
**
error
)
{
{
assert
(
encoder
->
open
);
assert
(
!
encoder
->
pre_tag
);
assert
(
!
encoder
->
tag
);
return
encoder
->
plugin
->
write
(
encoder
,
data
,
length
,
error
);
return
encoder
->
plugin
->
write
(
encoder
,
data
,
length
,
error
);
}
}
...
@@ -215,6 +264,16 @@ encoder_write(struct encoder *encoder, const void *data, size_t length,
...
@@ -215,6 +264,16 @@ encoder_write(struct encoder *encoder, const void *data, size_t length,
static
inline
size_t
static
inline
size_t
encoder_read
(
struct
encoder
*
encoder
,
void
*
dest
,
size_t
length
)
encoder_read
(
struct
encoder
*
encoder
,
void
*
dest
,
size_t
length
)
{
{
assert
(
encoder
->
open
);
assert
(
!
encoder
->
pre_tag
||
!
encoder
->
tag
);
#ifndef NDEBUG
if
(
encoder
->
pre_tag
)
{
encoder
->
pre_tag
=
false
;
encoder
->
tag
=
true
;
}
#endif
return
encoder
->
plugin
->
read
(
encoder
,
dest
,
length
);
return
encoder
->
plugin
->
read
(
encoder
,
dest
,
length
);
}
}
...
...
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