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
e70cb62f
Commit
e70cb62f
authored
Apr 27, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor mpegts reader header handing -> support more than one entry.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
edd5c905
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
17 deletions
+51
-17
testmpegts.cc
src/testmpegts.cc
+51
-17
No files found.
src/testmpegts.cc
View file @
e70cb62f
...
@@ -19,11 +19,13 @@
...
@@ -19,11 +19,13 @@
#include <stdio.h>
#include <stdio.h>
#include <array>
#include <array>
#include <regex>
#include "utils.hh"
#include "utils.hh"
using
std
::
string
;
using
std
::
string
;
using
std
::
vector
;
using
std
::
vector
;
using
std
::
regex
;
class
TSPacket
class
TSPacket
{
{
...
@@ -168,18 +170,50 @@ public:
...
@@ -168,18 +170,50 @@ public:
vector
<
unsigned
char
>
data
;
vector
<
unsigned
char
>
data
;
};
};
private
:
private
:
struct
Header
{
string
filename
;
size_t
data_size
=
0
;
size_t
header_size
=
0
;
};
vector
<
Entry
>
m_entries
;
vector
<
Entry
>
m_entries
;
bool
parse_header
(
Header
&
header
,
const
vector
<
unsigned
char
>&
data
);
public
:
public
:
Error
load
(
const
string
&
inname
);
Error
load
(
const
string
&
inname
);
const
vector
<
Entry
>&
entries
();
const
vector
<
Entry
>&
entries
();
};
};
bool
TSReader
::
parse_header
(
Header
&
header
,
const
vector
<
unsigned
char
>&
data
)
{
for
(
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
{
if
(
data
[
i
]
==
0
)
// header is terminated with one single 0 byte
{
string
s
=
(
const
char
*
)
(
&
data
[
0
]);
static
const
regex
header_re
(
"([0-9]*):(.*)"
);
std
::
smatch
sm
;
if
(
regex_match
(
s
,
sm
,
header_re
))
{
header
.
header_size
=
i
+
1
;
// number of header bytes including 0 termination
header
.
data_size
=
atoi
(
sm
[
1
].
str
().
c_str
());
header
.
filename
=
sm
[
2
];
return
true
;
}
}
}
return
false
;
}
Error
Error
TSReader
::
load
(
const
string
&
inname
)
TSReader
::
load
(
const
string
&
inname
)
{
{
FILE
*
infile
=
fopen
(
inname
.
c_str
(),
"r"
);
FILE
*
infile
=
fopen
(
inname
.
c_str
(),
"r"
);
vector
<
unsigned
char
>
awmk_stream
;
vector
<
unsigned
char
>
awmk_stream
;
Header
header
;
bool
header_valid
=
false
;
while
(
!
feof
(
infile
))
while
(
!
feof
(
infile
))
{
{
TSPacket
p
;
TSPacket
p
;
...
@@ -192,29 +226,29 @@ TSReader::load (const string& inname)
...
@@ -192,29 +226,29 @@ TSReader::load (const string& inname)
}
}
else
else
{
{
if
(
p
.
has_id
(
TSPacket
::
awmk_file
)
||
p
.
has_id
(
TSPacket
::
awmk_data
))
if
(
p
.
has_id
(
TSPacket
::
awmk_file
)
||
p
.
has_id
(
TSPacket
::
awmk_data
))
{
{
for
(
size_t
i
=
12
;
i
<
p
.
size
();
i
++
)
for
(
size_t
i
=
12
;
i
<
p
.
size
();
i
++
)
awmk_stream
.
push_back
(
p
[
i
]);
awmk_stream
.
push_back
(
p
[
i
]);
}
}
}
int
end
=
-
1
;
for
(
size_t
i
=
0
;
i
<
awmk_stream
.
size
();
i
++
)
if
(
awmk_stream
[
i
]
==
0
)
{
end
=
i
+
1
;
break
;
}
if
(
end
>
0
)
if
(
!
header_valid
)
{
{
int
data_len
=
atoi
((
char
*
)
awmk_stream
.
data
());
if
(
parse_header
(
header
,
awmk_stream
))
awmk_stream
.
erase
(
awmk_stream
.
begin
(),
awmk_stream
.
begin
()
+
end
);
header_valid
=
true
;
awmk_stream
.
resize
(
data_len
);
}
// done? do we have enough bytes for the complete entry?
if
(
header_valid
&&
awmk_stream
.
size
()
>=
(
header
.
header_size
+
header
.
data_size
))
{
awmk_stream
.
erase
(
awmk_stream
.
begin
(),
awmk_stream
.
begin
()
+
header
.
header_size
);
awmk_stream
.
resize
(
header
.
data_size
);
m_entries
.
push_back
({
header
.
filename
,
awmk_stream
});
m_entries
.
push_back
({
"foo"
,
awmk_stream
});
header_valid
=
false
;
awmk_stream
.
clear
();
}
}
}
}
}
return
Error
::
Code
::
NONE
;
return
Error
::
Code
::
NONE
;
}
}
...
...
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