Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
83b09715
Commit
83b09715
authored
Jun 24, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testhls: access format context directly
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b234cdfc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
testhls.cc
src/testhls.cc
+19
-19
No files found.
src/testhls.cc
View file @
83b09715
...
...
@@ -129,13 +129,13 @@ struct HLSOutputStream {
SwrContext
*
m_swr_ctx
=
nullptr
;
void
add_stream
(
AV
FormatContext
*
oc
,
AV
Codec
**
codec
,
enum
AVCodecID
codec_id
);
void
open_audio
(
AV
FormatContext
*
oc
,
AV
Codec
*
codec
,
AVDictionary
*
opt_arg
);
void
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
);
void
open_audio
(
AVCodec
*
codec
,
AVDictionary
*
opt_arg
);
AVFrame
*
get_audio_frame
();
int
write_audio_frame
(
AVFormatContext
*
oc
);
void
close_stream
(
AVFormatContext
*
oc
);
int
write_audio_frame
(
);
void
close_stream
(
);
AVFrame
*
alloc_audio_frame
(
enum
AVSampleFormat
sample_fmt
,
uint64_t
channel_layout
,
int
sample_rate
,
int
nb_samples
);
int
write_frame
(
AVFormatContext
*
fmt_ctx
,
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
);
int
write_frame
(
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
);
Error
open
(
const
string
&
output_filename
);
void
write
();
...
...
@@ -145,7 +145,7 @@ struct HLSOutputStream {
/* Add an output stream. */
void
HLSOutputStream
::
add_stream
(
AV
FormatContext
*
oc
,
AV
Codec
**
codec
,
enum
AVCodecID
codec_id
)
HLSOutputStream
::
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
)
{
AVCodecContext
*
c
;
int
i
;
...
...
@@ -158,12 +158,12 @@ HLSOutputStream::add_stream (AVFormatContext *oc, AVCodec **codec, enum AVCodecI
exit
(
1
);
}
m_st
=
avformat_new_stream
(
oc
,
NULL
);
m_st
=
avformat_new_stream
(
m_fmt_ctx
,
NULL
);
if
(
!
m_st
)
{
fprintf
(
stderr
,
"Could not allocate stream
\n
"
);
exit
(
1
);
}
m_st
->
id
=
oc
->
nb_streams
-
1
;
m_st
->
id
=
m_fmt_ctx
->
nb_streams
-
1
;
c
=
avcodec_alloc_context3
(
*
codec
);
if
(
!
c
)
{
fprintf
(
stderr
,
"Could not alloc an encoding context
\n
"
);
...
...
@@ -202,7 +202,7 @@ HLSOutputStream::add_stream (AVFormatContext *oc, AVCodec **codec, enum AVCodecI
}
/* Some formats want stream headers to be separate. */
if
(
oc
->
oformat
->
flags
&
AVFMT_GLOBALHEADER
)
if
(
m_fmt_ctx
->
oformat
->
flags
&
AVFMT_GLOBALHEADER
)
c
->
flags
|=
AV_CODEC_FLAG_GLOBAL_HEADER
;
}
...
...
@@ -236,7 +236,7 @@ HLSOutputStream::alloc_audio_frame(enum AVSampleFormat sample_fmt, uint64_t chan
void
HLSOutputStream
::
open_audio
(
AV
FormatContext
*
oc
,
AV
Codec
*
codec
,
AVDictionary
*
opt_arg
)
HLSOutputStream
::
open_audio
(
AVCodec
*
codec
,
AVDictionary
*
opt_arg
)
{
AVCodecContext
*
c
;
int
nb_samples
;
...
...
@@ -332,14 +332,14 @@ HLSOutputStream::get_audio_frame()
int
HLSOutputStream
::
write_frame
(
AVFormatContext
*
fmt_ctx
,
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
)
HLSOutputStream
::
write_frame
(
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
)
{
/* rescale output packet timestamp values from codec to stream timebase */
av_packet_rescale_ts
(
pkt
,
*
time_base
,
st
->
time_base
);
pkt
->
stream_index
=
st
->
index
;
/* Write the compressed frame to the media file. */
return
av_interleaved_write_frame
(
fmt_ctx
,
pkt
);
return
av_interleaved_write_frame
(
m_
fmt_ctx
,
pkt
);
}
...
...
@@ -348,7 +348,7 @@ HLSOutputStream::write_frame (AVFormatContext *fmt_ctx, const AVRational *time_b
* return 1 when encoding is finished, 0 otherwise
*/
int
HLSOutputStream
::
write_audio_frame
(
AVFormatContext
*
oc
)
HLSOutputStream
::
write_audio_frame
(
)
{
AVCodecContext
*
c
;
AVPacket
pkt
=
{
0
};
// data and size must be 0;
...
...
@@ -405,7 +405,7 @@ HLSOutputStream::write_audio_frame (AVFormatContext *oc)
}
else
if
(
m_keep_frames
)
{
ret
=
write_frame
(
oc
,
&
c
->
time_base
,
m_st
,
&
pkt
);
ret
=
write_frame
(
&
c
->
time_base
,
m_st
,
&
pkt
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error while writing audio frame: %s
\n
"
,
...
...
@@ -420,7 +420,7 @@ HLSOutputStream::write_audio_frame (AVFormatContext *oc)
}
void
HLSOutputStream
::
close_stream
(
AVFormatContext
*
oc
)
HLSOutputStream
::
close_stream
(
)
{
avcodec_free_context
(
&
m_enc
);
av_frame_free
(
&
m_frame
);
...
...
@@ -448,8 +448,8 @@ HLSOutputStream::open (const string& out_filename)
AVDictionary
*
opt
=
nullptr
;
AVCodec
*
audio_codec
;
add_stream
(
m_fmt_ctx
,
&
audio_codec
,
AV_CODEC_ID_AAC
);
open_audio
(
m_fmt_ctx
,
audio_codec
,
opt
);
add_stream
(
&
audio_codec
,
AV_CODEC_ID_AAC
);
open_audio
(
audio_codec
,
opt
);
/* Write the stream header, if any. */
ret
=
avformat_write_header
(
m_fmt_ctx
,
&
opt
);
...
...
@@ -467,7 +467,7 @@ HLSOutputStream::close()
{
av_write_trailer
(
m_fmt_ctx
);
close_stream
(
m_fmt_ctx
);
close_stream
(
);
/* Close the output file. */
if
(
!
(
m_fmt_ctx
->
oformat
->
flags
&
AVFMT_NOFILE
))
...
...
@@ -482,7 +482,7 @@ HLSOutputStream::close()
void
HLSOutputStream
::
write
()
{
while
(
write_audio_frame
(
m_fmt_ctx
)
==
0
);
while
(
write_audio_frame
(
)
==
0
);
}
Error
...
...
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