Skip to content

Commit b604451

Browse files
committed
added utility functions for splitting
1 parent 73cb087 commit b604451

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

include/ffmpeg_encoder_decoder/utils.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ std::vector<std::string> split_by_char(const std::string & str_list, const char
175175
* \return true if ROS encoding is single channel and color format is like NV12/yuv420p
176176
*/
177177
bool encode_single_channel_as_color(const std::string & encoding, enum AVPixelFormat fmt);
178+
179+
/**
180+
* \brief splits a string with a list of decoders
181+
* \param decoder_list comma-separated list of decoders
182+
* \return vector of separated strings
183+
*/
184+
std::vector<std::string> split_decoders(const std::string & decoder_list);
185+
186+
/**
187+
* \brief splits a string with an encoding ("codec;fmt;fmt;fmt")
188+
* \param encoding string with encoding information
189+
* \return vector of separated strings
190+
*/
191+
std::vector<std::string> split_encoding(const std::string & encoding);
192+
178193
} // namespace utils
179194
} // namespace ffmpeg_encoder_decoder
180195
#endif // FFMPEG_ENCODER_DECODER__UTILS_HPP_

src/decoder.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,10 @@ void Decoder::setOutputMessageEncoding(const std::string & output_encoding)
6666
outputMsgEncoding_ = output_encoding;
6767
}
6868

69-
static std::vector<std::string> splitEncoding(const std::string & encoding)
70-
{
71-
return (utils::split_by_char(encoding, ';'));
72-
}
73-
7469
void Decoder::setEncoding(const std::string & encoding)
7570
{
7671
packetEncoding_ = encoding;
77-
const auto split = splitEncoding(encoding);
72+
const auto split = ffmpeg_encoder_decoder::utils::split_encoding(encoding);
7873
if (outputMsgEncoding_.empty()) {
7974
// assume orig was bgr8
8075
outputMsgEncoding_ = split.size() == 4 ? split[3] : "bgr8";

src/utils.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ std::vector<std::string> split_by_char(const std::string & str_list, const char
266266
return (split);
267267
}
268268

269+
std::vector<std::string> split_decoders(const std::string & decoder_list)
270+
{
271+
return (split_by_char(decoder_list, ','));
272+
}
273+
274+
std::vector<std::string> split_encoding(const std::string & encoding)
275+
{
276+
return (split_by_char(encoding, ';'));
277+
}
278+
269279
// This function finds the encoding that is the target of a given encoder.
270280

271281
static AVCodecID find_id_for_encoder_or_encoding(const std::string & encoder)
@@ -313,8 +323,8 @@ std::string find_decoders(const std::string & codec)
313323
std::string filter_decoders(const std::string & codec, const std::string & decoders)
314324
{
315325
std::string filtered;
316-
const auto valid_decoders = split_by_char(find_decoders(codec), ',');
317-
for (const auto & dec : split_by_char(decoders, ',')) {
326+
const auto valid_decoders = split_decoders(find_decoders(codec));
327+
for (const auto & dec : split_decoders(decoders)) {
318328
bool found = false;
319329
for (const auto & valid : valid_decoders) {
320330
if (dec == valid) {

0 commit comments

Comments
 (0)