Skip to content

Commit

Permalink
fix python 2.7 on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
markreidvfx committed Jun 13, 2022
1 parent 38a664e commit 391e432
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 32 deletions.
43 changes: 29 additions & 14 deletions avb/_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ from cython.operator cimport dereference as deref, preincrement as inc
cimport cython

IF UNAME_SYSNAME == "Windows":
ctypedef unsigned char uint8_t
ctypedef signed short int16_t

ctypedef signed int int32_t
ctypedef unsigned int uint32_t
cdef extern from *:
ctypedef unsigned char uint8_t
ctypedef signed char int8_t

ctypedef unsigned short uint16_t
ctypedef signed short int16_t

ctypedef signed int int32_t
ctypedef unsigned int uint32_t

ctypedef signed long long int int64_t
ctypedef unsigned long long int uint64_t

ctypedef signed long long int int64_t
ctypedef unsigned long long int uint64_t
ELSE:
from libc.stdint cimport (uint8_t, int16_t, uint32_t, int32_t,uint64_t, int64_t)

Expand Down Expand Up @@ -52,12 +58,16 @@ cdef extern from "_ext_core.cpp" nogil:
cdef enum ControlPointValueType:
CP_TYPE_INT,
CP_TYPE_DOUBLE,
CP_TYPE_REFERENCE,
CP_TYPE_REFERENCE

cdef union IntDataValue:
uint64_t u64
int64_t s64

cdef struct IntData:
const char *name
bint is_signed;
uint64_t data
IntDataValue data

cdef struct IntArrayData:
const char *name
Expand Down Expand Up @@ -147,6 +157,8 @@ cdef extern from "_ext_core.cpp" nogil:
cdef int read_cdci_descriptor(Buffer *f, Properties *p) except+
cdef int read_effectparamlist(Buffer *f, Properties *p) except+

cdef void check_internal_sizes()

cdef class AVBPropertyData(dict):

def deref(self, value):
Expand All @@ -167,7 +179,7 @@ cdef class AVBPropertyData(dict):
cdef void refs2dict(object root, dict d, Properties* p):
cdef IntData item
for item in p.refs:
d[item.name.decode('utf-8')] = AVBObjectRef(root, item.data)
d[item.name.decode('utf-8')] = AVBObjectRef(root, item.data.u64)

cdef void reflist2dict(object root, dict d, Properties* p):
cdef RefListData item
Expand Down Expand Up @@ -242,14 +254,14 @@ cdef void ints2dict(dict d, Properties* p):
cdef int64_t signed_value
for item in p.ints:
if item.is_signed:
d[item.name.decode('utf-8')] = <int64_t>item.data
d[item.name.decode('utf-8')] = item.data.s64
else:
d[item.name.decode('utf-8')] = item.data
d[item.name.decode('utf-8')] = item.data.u64

cdef void dates2dict(dict d, Properties* p):
cdef IntData item
for item in p.dates:
d[item.name.decode('utf-8')] = datetime.fromtimestamp(item.data)
d[item.name.decode('utf-8')] = datetime.fromtimestamp(item.data.u64)

cdef void doubles2dict(dict d, Properties *p):
cdef DoubleData item
Expand Down Expand Up @@ -341,9 +353,12 @@ cdef void bytearray2dict(dict d, Properties *p):
cdef uint8_t *ptr
cdef size_t size
for item in p.bytearrays:
ptr = &item.data[0]
size = item.data.size()
d[item.name.decode('utf-8')] = <bytearray> ptr[:size]
if size:
ptr = &item.data[0]
d[item.name.decode('utf-8')] = <bytearray> ptr[:size]
else:
d[item.name.decode('utf-8')] = bytearray()

cdef dict process_poperties(object root, Properties *p):
cdef dict result = AVBPropertyData()
Expand Down
43 changes: 27 additions & 16 deletions avb/_ext_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
typedef unsigned char uint8_t;
typedef signed char int8_t;

typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;

typedef signed int int32_t;
typedef unsigned int uint32_t;
Expand Down Expand Up @@ -70,10 +70,15 @@ enum PropertyType {
PARAM,
};

union IntDataValue {
uint64_t u64;
int64_t s64;
};

struct IntData {
const char *name;
uint64_t data;
bool is_signed;
IntDataValue data;
};

struct DoubleData {
Expand Down Expand Up @@ -269,7 +274,7 @@ static inline void add_object_ref(Properties *p, const char* name, uint64_t valu
IntData d = {};

d.name = name;
d.data = value;
d.data.u64 = value;
p->refs.push_back(d);
}

Expand All @@ -278,7 +283,7 @@ static inline void add_uint(Properties *p, const char* name, uint64_t value)
IntData d = {};

d.name = name;
d.data = value;
d.data.u64 = value;
p->ints.push_back(d);
}

Expand All @@ -287,7 +292,7 @@ static inline void add_int(Properties *p, const char* name, int64_t value)
IntData d = {};

d.name = name;
d.data = value;
d.data.s64 = value;
d.is_signed = true;
p->ints.push_back(d);
}
Expand All @@ -307,7 +312,7 @@ static inline void add_date(Properties *p, const char* name, uint64_t value)
IntData d = {};

d.name = name;
d.data = value;
d.data.u64 = value;
p->dates.push_back(d);
}

Expand All @@ -328,9 +333,10 @@ static inline int read_mob_id(Properties *p, Buffer *f, const char* name)
uint8_t *m = &mob_id.data[0];

read_assert_tag(f, 65);
int smpte_label_len = read_u32le(f);
uint32_t smpte_label_len = read_u32le(f);

if(smpte_label_len != 12)
return -1;
return -1;

for (int i =0; i < 12; i++) {
*m++ = read_u8(f);
Expand Down Expand Up @@ -364,7 +370,7 @@ static inline int read_mob_id(Properties *p, Buffer *f, const char* name)
*m++ = read_u8(f);

read_assert_tag(f, 65);
int data4len = read_u32le(f);
uint32_t data4len = read_u32le(f);
if(data4len != 8) {
return -1;
}
Expand Down Expand Up @@ -449,7 +455,7 @@ static int read_sequence(Buffer *f, Properties *p)
read_assert_tag(f, 0x02);
read_assert_tag(f, 0x03);

size_t count = (int32_t)read_u32le(f);
uint32_t count = read_u32le(f);
p->reflists.push_back(RefListData());
RefListData &reflist = p->reflists[p->reflists.size()-1];
reflist.name = "components";
Expand All @@ -467,7 +473,7 @@ static int read_clip(Buffer *f, Properties *p)
read_comp(f, p);
read_assert_tag(f, 0x02);
read_assert_tag(f, 0x01);
add_int(p, "length", (int32_t)read_u32le(f));
add_uint(p, "length", read_u32le(f)); // should this be a int?

return 0;
}
Expand Down Expand Up @@ -524,7 +530,7 @@ static int read_paramclip(Buffer *f, Properties *p)
ControlPointValueType value_type = (ControlPointValueType)read_u16le(f);
add_int(p, "value_type", value_type);

size_t point_count = read_u32le(f);
uint32_t point_count = read_u32le(f);

p->control_points.resize(1);
ControlPointData *cp_data = &p->control_points[0];
Expand Down Expand Up @@ -554,7 +560,7 @@ static int read_paramclip(Buffer *f, Properties *p)
return -1;
}

int16_t pp_count = read_u16le(f);
uint16_t pp_count = read_u16le(f);
cp->pp.resize(pp_count);
for(int j = 0; j < pp_count; j++) {
PerPoint *pp = &cp->pp[j];
Expand Down Expand Up @@ -1119,7 +1125,7 @@ static int read_effectparamlist(Buffer *f, Properties *p)
add_int(p, "orig_length", (int32_t)read_u32le(f));
add_int(p, "window_offset", (int32_t)read_u32le(f));

size_t parameter_count = read_u32le(f);
uint32_t parameter_count = read_u32le(f);
add_int(p, "keyframe_size", (int32_t)read_u32le(f));

p->children.push_back(Properties::ChildData());
Expand All @@ -1130,6 +1136,7 @@ static int read_effectparamlist(Buffer *f, Properties *p)
parameters.resize(parameter_count);

for (size_t i = 0; i < parameter_count; i++) {

Properties &param = parameters[i];
param.type = PARAM;

Expand Down Expand Up @@ -1171,15 +1178,15 @@ static int read_effectparamlist(Buffer *f, Properties *p)

add_int(&param, "enable_key_flags", (int8_t)read_u8(f));

size_t color_count =read_u32le(f);
uint32_t color_count =read_u32le(f);
vector<int64_t> &colors = add_int_array(&param, "colors");
colors.reserve(color_count);

for (size_t j=0; j < color_count; j++) {
colors.push_back((int32_t)read_u32le(f));
}

size_t param_size = read_u32le(f);
uint32_t param_size = read_u32le(f);
vector<uint8_t> &user_param = add_bytearray(&param, "user_param");
user_param.resize(param_size);
for (size_t j=0; j < param_size; j++) {
Expand All @@ -1191,6 +1198,7 @@ static int read_effectparamlist(Buffer *f, Properties *p)
}

read_assert_tag(f, 0x03);

return 0;
}

Expand All @@ -1203,6 +1211,9 @@ static int read_attributes(Buffer *f, std::vector<AttrData> &d)
size_t attr_count = read_u32le(f);
d.resize(attr_count);

if (attr_count == 0)
return 0;

AttrData *ptr = &d[0];

for(size_t i =0; i < attr_count; i++) {
Expand Down
9 changes: 7 additions & 2 deletions avb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
division,
)

from . import utils
import sys
from collections import OrderedDict
from . import utils

sentinel = object()

INT_FORMAT = int
if sys.version_info.major < 3:
INT_FORMAT = (int, long)

class AVBPropertyDef(object):
__slots__ = ('name', 'long_name', 'type', 'default')
def __init__(self, name, long_name, data_type, default_value=sentinel):
Expand Down Expand Up @@ -94,7 +99,7 @@ def reverse(self):
self.mark_modified()

def deref(self, value):
if isinstance(value, int):
if isinstance(value, INT_FORMAT):
return utils.AVBObjectRef(self.root, value).value

if isinstance(value, utils.AVBObjectRef):
Expand Down

0 comments on commit 391e432

Please sign in to comment.