mirror of
https://github.com/fmang/opustags.git
synced 2024-11-10 07:27:22 +01:00
store the vendor as a string_view
This commit is contained in:
parent
590a6814dd
commit
d9b96d471d
14
src/opus.cc
14
src/opus.cc
@ -43,9 +43,9 @@ int ot::parse_tags(const char *data, long len, opus_tags *tags)
|
||||
return -1;
|
||||
// Vendor
|
||||
pos = 8;
|
||||
tags->vendor_length = le32toh(*((uint32_t*) (data + pos)));
|
||||
tags->vendor_string = data + pos + 4;
|
||||
pos += 4 + tags->vendor_length;
|
||||
tags->vendor.size = le32toh(*((uint32_t*) (data + pos)));
|
||||
tags->vendor.data = data + pos + 4;
|
||||
pos += 4 + tags->vendor.size;
|
||||
if (pos + 4 > len)
|
||||
return -1;
|
||||
// Count
|
||||
@ -72,7 +72,7 @@ int ot::render_tags(opus_tags *tags, ogg_packet *op)
|
||||
op->e_o_s = 0;
|
||||
op->granulepos = 0;
|
||||
op->packetno = 1;
|
||||
long len = 8 + 4 + tags->vendor_length + 4;
|
||||
long len = 8 + 4 + tags->vendor.size + 4;
|
||||
for (const string_view &comment : tags->comments)
|
||||
len += 4 + comment.size;
|
||||
len += tags->extra_data.size;
|
||||
@ -83,10 +83,10 @@ int ot::render_tags(opus_tags *tags, ogg_packet *op)
|
||||
op->packet = (unsigned char*) data;
|
||||
uint32_t n;
|
||||
memcpy(data, "OpusTags", 8);
|
||||
n = htole32(tags->vendor_length);
|
||||
n = htole32(tags->vendor.size);
|
||||
memcpy(data+8, &n, 4);
|
||||
memcpy(data+12, tags->vendor_string, tags->vendor_length);
|
||||
data += 12 + tags->vendor_length;
|
||||
memcpy(data+12, tags->vendor.data, tags->vendor.size);
|
||||
data += 12 + tags->vendor.size;
|
||||
n = htole32(tags->comments.size());
|
||||
memcpy(data, &n, 4);
|
||||
data += 4;
|
||||
|
@ -49,9 +49,11 @@ int write_page(ogg_page *og, FILE *stream);
|
||||
* Represent all the data in an OpusTags packet.
|
||||
*/
|
||||
struct opus_tags {
|
||||
uint32_t vendor_length;
|
||||
/** \todo Convert to a string view. */
|
||||
const char *vendor_string;
|
||||
/**
|
||||
* OpusTags packets begin with a vendor string, meant to identify the
|
||||
* implementation of the encoder. It is an arbitrary UTF-8 string.
|
||||
*/
|
||||
string_view vendor;
|
||||
/**
|
||||
* Comments. These are a list of string following the NAME=Value format.
|
||||
* A comment may also be called a field, or a tag.
|
||||
|
@ -42,10 +42,8 @@ static bool parse_standard()
|
||||
int rc = ot::parse_tags(standard_OpusTags, sizeof(standard_OpusTags) - 1, &tags);
|
||||
if (rc != 0)
|
||||
throw failure("ot::parse_tags did not return 0");
|
||||
if (tags.vendor_length != 20)
|
||||
throw failure("the vendor string length is invalid");
|
||||
if (memcmp(tags.vendor_string, "opustags test packet", 20) != 0)
|
||||
throw failure("the vendor string is invalid");
|
||||
if (tags.vendor != ot::string_view( "opustags test packet"))
|
||||
throw failure("bad vendor string");
|
||||
if (tags.comments.size() != 2)
|
||||
throw failure("bad number of comments");
|
||||
auto it = tags.comments.begin();
|
||||
|
Loading…
Reference in New Issue
Block a user