mirror of
https://github.com/mpv-player/mpv
synced 2025-01-13 00:06:25 +01:00
bstr.[ch]: add new files for struct bstr related functionality
Move "struct bstr" definition from ebml.h to its own header and add some utility functions/macros. Change length field type from int to size_t and adjust using code accordingly. Partially based on a patch from Anton Khirnov.
This commit is contained in:
parent
c67d3dfcfc
commit
d72541b75c
1
Makefile
1
Makefile
@ -331,6 +331,7 @@ SRCS_COMMON-$(ZR) += libmpcodecs/vd_zrmjpeg.c \
|
||||
libmpcodecs/vf_zrmjpeg.c
|
||||
SRCS_COMMON = asxparser.c \
|
||||
av_log.c \
|
||||
bstr.c \
|
||||
codec-cfg.c \
|
||||
cpudetect.c \
|
||||
defaultopts.c \
|
||||
|
51
bstr.c
Normal file
51
bstr.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer 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.
|
||||
*
|
||||
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <libavutil/avutil.h>
|
||||
#include "bstr.h"
|
||||
|
||||
int bstrcmp(struct bstr str1, struct bstr str2)
|
||||
{
|
||||
int ret = memcmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
|
||||
|
||||
if (!ret) {
|
||||
if (str1.len == str2.len)
|
||||
return 0;
|
||||
else if (str1.len > str2.len)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bstrcasecmp(struct bstr str1, struct bstr str2)
|
||||
{
|
||||
int ret = strncasecmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
|
||||
|
||||
if (!ret) {
|
||||
if (str1.len == str2.len)
|
||||
return 0;
|
||||
else if (str1.len > str2.len)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
39
bstr.h
Normal file
39
bstr.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer 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.
|
||||
*
|
||||
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPLAYER_BSTR_H
|
||||
#define MPLAYER_BSTR_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
struct bstr {
|
||||
const uint8_t *start;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
int bstrcmp(struct bstr str1, struct bstr str2);
|
||||
int bstrcasecmp(struct bstr str1, struct bstr str2);
|
||||
|
||||
// Create bstr compound literal from null-terminated string
|
||||
#define BSTR(s) (struct bstr){(s), (s) ? strlen(s) : 0}
|
||||
// create a pair (not single value!) for "%.*s" printf syntax
|
||||
#define BSTR_P(bstr) (int)((bstr).len), (bstr).start
|
||||
|
||||
#endif /* MPLAYER_BSTR_H */
|
@ -862,7 +862,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
|
||||
(int) ((chapter.end / 60 / 1000) % 60),
|
||||
(int) ((chapter.end / 1000) % 60),
|
||||
(int) (chapter.end % 1000),
|
||||
name.len, name.start);
|
||||
BSTR_P(name));
|
||||
|
||||
if (idx == selected_edition){
|
||||
demuxer_add_chapter(demuxer, name.start, name.len,
|
||||
@ -920,7 +920,7 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer)
|
||||
demuxer_add_attachment(demuxer, name.start, name.len, mime.start,
|
||||
mime.len, data, data_size);
|
||||
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Attachment: %.*s, %.*s, %u bytes\n",
|
||||
name.len, name.start, mime.len, mime.start, data_size);
|
||||
BSTR_P(name), BSTR_P(mime), data_size);
|
||||
}
|
||||
|
||||
out:
|
||||
|
@ -612,9 +612,9 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target,
|
||||
strptr->len = length;
|
||||
if (ed->type == EBML_TYPE_STR)
|
||||
mp_msg(MSGT_DEMUX, MSGL_DBG2, "string \"%.*s\"\n",
|
||||
strptr->len, strptr->start);
|
||||
BSTR_P(*strptr));
|
||||
else
|
||||
mp_msg(MSGT_DEMUX, MSGL_DBG2, "binary %d bytes\n",
|
||||
mp_msg(MSGT_DEMUX, MSGL_DBG2, "binary %zd bytes\n",
|
||||
strptr->len);
|
||||
break;
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "stream/stream.h"
|
||||
#include "bstr.h"
|
||||
|
||||
|
||||
/* EBML version supported */
|
||||
@ -62,11 +63,6 @@ struct ebml_parse_ctx {
|
||||
bool no_error_messages;
|
||||
};
|
||||
|
||||
struct bstr {
|
||||
uint8_t *start;
|
||||
int len;
|
||||
};
|
||||
|
||||
#include "ebml_types.h"
|
||||
|
||||
#define EBML_ID_INVALID 0xffffffff
|
||||
|
Loading…
Reference in New Issue
Block a user