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
05f7a6d1
Commit
05f7a6d1
authored
Mar 13, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/ffmpeg: add AVFormatContext wrapper class
parent
0256bbbb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
19 deletions
+87
-19
FfmpegDecoderPlugin.cxx
src/decoder/plugins/FfmpegDecoderPlugin.cxx
+6
-19
Format.hxx
src/lib/ffmpeg/Format.hxx
+81
-0
No files found.
src/decoder/plugins/FfmpegDecoderPlugin.cxx
View file @
05f7a6d1
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include "lib/ffmpeg/Init.hxx"
#include "lib/ffmpeg/Init.hxx"
#include "lib/ffmpeg/Buffer.hxx"
#include "lib/ffmpeg/Buffer.hxx"
#include "lib/ffmpeg/Frame.hxx"
#include "lib/ffmpeg/Frame.hxx"
#include "lib/ffmpeg/Format.hxx"
#include "../DecoderAPI.hxx"
#include "../DecoderAPI.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegIo.hxx"
#include "FfmpegIo.hxx"
...
@@ -58,24 +59,18 @@ extern "C" {
...
@@ -58,24 +59,18 @@ extern "C" {
*/
*/
static
AVDictionary
*
avformat_options
=
nullptr
;
static
AVDictionary
*
avformat_options
=
nullptr
;
static
AVFormatContext
*
static
Ffmpeg
::
FormatContext
FfmpegOpenInput
(
AVIOContext
*
pb
,
FfmpegOpenInput
(
AVIOContext
*
pb
,
const
char
*
filename
,
const
char
*
filename
,
AVInputFormat
*
fmt
)
AVInputFormat
*
fmt
)
{
{
AVFormatContext
*
context
=
avformat_alloc_context
();
Ffmpeg
::
FormatContext
context
(
pb
);
if
(
context
==
nullptr
)
throw
std
::
runtime_error
(
"avformat_alloc_context() failed"
);
context
->
pb
=
pb
;
AVDictionary
*
options
=
nullptr
;
AVDictionary
*
options
=
nullptr
;
AtScopeExit
(
&
options
)
{
av_dict_free
(
&
options
);
};
AtScopeExit
(
&
options
)
{
av_dict_free
(
&
options
);
};
av_dict_copy
(
&
options
,
avformat_options
,
0
);
av_dict_copy
(
&
options
,
avformat_options
,
0
);
int
err
=
avformat_open_input
(
&
context
,
filename
,
fmt
,
&
options
);
context
.
OpenInput
(
filename
,
fmt
,
&
options
);
if
(
err
<
0
)
throw
MakeFfmpegError
(
err
,
"avformat_open_input() failed"
);
return
context
;
return
context
;
}
}
...
@@ -628,13 +623,9 @@ ffmpeg_decode(DecoderClient &client, InputStream &input)
...
@@ -628,13 +623,9 @@ ffmpeg_decode(DecoderClient &client, InputStream &input)
return
;
return
;
}
}
AVFormatContext
*
format_context
=
auto
format_context
=
FfmpegOpenInput
(
stream
.
io
,
input
.
GetURI
(),
nullptr
);
FfmpegOpenInput
(
stream
.
io
,
input
.
GetURI
(),
nullptr
);
AtScopeExit
(
&
format_context
)
{
avformat_close_input
(
&
format_context
);
};
const
auto
*
input_format
=
format_context
->
iformat
;
const
auto
*
input_format
=
format_context
->
iformat
;
FormatDebug
(
ffmpeg_domain
,
"detected input format '%s' (%s)"
,
FormatDebug
(
ffmpeg_domain
,
"detected input format '%s' (%s)"
,
input_format
->
name
,
input_format
->
long_name
);
input_format
->
name
,
input_format
->
long_name
);
...
@@ -683,11 +674,7 @@ try {
...
@@ -683,11 +674,7 @@ try {
if
(
!
stream
.
Open
())
if
(
!
stream
.
Open
())
return
false
;
return
false
;
AVFormatContext
*
f
=
FfmpegOpenInput
(
stream
.
io
,
is
.
GetURI
(),
nullptr
);
auto
f
=
FfmpegOpenInput
(
stream
.
io
,
is
.
GetURI
(),
nullptr
);
AtScopeExit
(
&
f
)
{
avformat_close_input
(
&
f
);
};
return
FfmpegScanStream
(
*
f
,
handler
);
return
FfmpegScanStream
(
*
f
,
handler
);
}
catch
(...)
{
}
catch
(...)
{
return
false
;
return
false
;
...
...
src/lib/ffmpeg/Format.hxx
0 → 100644
View file @
05f7a6d1
/*
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_FFMPEG_FORMAT_HXX
#define MPD_FFMPEG_FORMAT_HXX
#include "Error.hxx"
extern
"C"
{
#include <libavformat/avformat.h>
}
#include <new>
namespace
Ffmpeg
{
class
FormatContext
{
AVFormatContext
*
format_context
=
nullptr
;
public
:
FormatContext
()
=
default
;
explicit
FormatContext
(
AVIOContext
*
pb
)
:
format_context
(
avformat_alloc_context
())
{
if
(
format_context
==
nullptr
)
throw
std
::
bad_alloc
();
format_context
->
pb
=
pb
;
}
~
FormatContext
()
noexcept
{
if
(
format_context
!=
nullptr
)
avformat_close_input
(
&
format_context
);
}
FormatContext
(
FormatContext
&&
src
)
noexcept
:
format_context
(
std
::
exchange
(
src
.
format_context
,
nullptr
))
{}
FormatContext
&
operator
=
(
FormatContext
&&
src
)
noexcept
{
using
std
::
swap
;
swap
(
format_context
,
src
.
format_context
);
return
*
this
;
}
void
OpenInput
(
const
char
*
url
,
AVInputFormat
*
fmt
,
AVDictionary
**
options
)
{
int
err
=
avformat_open_input
(
&
format_context
,
url
,
fmt
,
options
);
if
(
err
<
0
)
throw
MakeFfmpegError
(
err
,
"avformat_open_input() failed"
);
}
AVFormatContext
&
operator
*
()
noexcept
{
return
*
format_context
;
}
AVFormatContext
*
operator
->
()
noexcept
{
return
format_context
;
}
};
}
// namespace Ffmpeg
#endif
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