Clean up MP42Track a bit.
This commit is contained in:
1 parent
fe908428f4
commit
1d100a1db0
20 files changed
+190
-137
No files matched your search
+112
-93
@@ -14,25 +14,24 @@
|
||||
|
||||
@implementation MP42VideoTrack
|
||||
{
|
||||
uint64_t width, height;
|
||||
float trackWidth, trackHeight;
|
||||
uint64_t _width, _height;
|
||||
float _trackWidth, _trackHeight;
|
||||
|
||||
// Pixel Aspect Ratio
|
||||
uint64_t hSpacing, vSpacing;
|
||||
uint64_t _hSpacing, _vSpacing;
|
||||
|
||||
// Clean Aperture
|
||||
uint64_t cleanApertureWidthN, cleanApertureWidthD;
|
||||
uint64_t cleanApertureHeightN, cleanApertureHeightD;
|
||||
uint64_t horizOffN, horizOffD;
|
||||
uint64_t vertOffN, vertOffD;
|
||||
uint64_t _cleanApertureWidthN, _cleanApertureWidthD;
|
||||
uint64_t _cleanApertureHeightN, _cleanApertureHeightD;
|
||||
uint64_t _horizOffN, _horizOffD;
|
||||
uint64_t _vertOffN, _vertOffD;
|
||||
|
||||
// Matrix
|
||||
uint32_t offsetX, offsetY;
|
||||
uint32_t _offsetX, _offsetY;
|
||||
|
||||
// H.264 profile
|
||||
uint8_t _origProfile, _origLevel;
|
||||
uint8_t _newProfile, _newLevel;
|
||||
|
||||
}
|
||||
|
||||
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle
|
||||
@@ -42,14 +41,14 @@
|
||||
if (self) {
|
||||
|
||||
if ([self isMemberOfClass:[MP42VideoTrack class]]) {
|
||||
height = MP4GetTrackVideoHeight(fileHandle, _trackId);
|
||||
width = MP4GetTrackVideoWidth(fileHandle, _trackId);
|
||||
_height = MP4GetTrackVideoHeight(fileHandle, _trackId);
|
||||
_width = MP4GetTrackVideoWidth(fileHandle, _trackId);
|
||||
}
|
||||
|
||||
_mediaType = kMP42MediaType_Video;
|
||||
|
||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", &trackWidth);
|
||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", &trackHeight);
|
||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", &_trackWidth);
|
||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", &_trackHeight);
|
||||
|
||||
uint8_t *val;
|
||||
uint8_t nval[36];
|
||||
@@ -58,28 +57,28 @@
|
||||
|
||||
MP4GetTrackBytesProperty(fileHandle ,_trackId, "tkhd.matrix", &val, &size);
|
||||
memcpy(nval, val, size);
|
||||
offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
||||
offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
||||
_offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
||||
_offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
||||
free(val);
|
||||
|
||||
if (MP4HaveTrackAtom(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp")) {
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", &hSpacing);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", &vSpacing);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", &_hSpacing);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", &_vSpacing);
|
||||
}
|
||||
else {
|
||||
hSpacing = 1;
|
||||
vSpacing = 1;
|
||||
_hSpacing = 1;
|
||||
_vSpacing = 1;
|
||||
}
|
||||
|
||||
if (MP4HaveTrackAtom(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap")) {
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", &cleanApertureWidthN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", &cleanApertureWidthD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", &cleanApertureHeightN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", &cleanApertureHeightD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", &horizOffN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", &horizOffD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", &vertOffN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", &vertOffD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", &_cleanApertureWidthN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", &_cleanApertureWidthD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", &_cleanApertureHeightN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", &_cleanApertureHeightD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", &_horizOffN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", &_horizOffD);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", &_vertOffN);
|
||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", &_vertOffD);
|
||||
}
|
||||
|
||||
if (_format == kMP42VideoCodecType_H264) {
|
||||
@@ -111,9 +110,9 @@
|
||||
if (_trackId) {
|
||||
[super writeToFile:fileHandle error:outError];
|
||||
|
||||
if (trackWidth > 0 && trackHeight > 0) {
|
||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", trackWidth);
|
||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", trackHeight);
|
||||
if (_trackWidth > 0 && _trackHeight > 0) {
|
||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", _trackWidth);
|
||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", _trackHeight);
|
||||
|
||||
uint8_t *val;
|
||||
uint8_t nval[36];
|
||||
@@ -122,49 +121,49 @@
|
||||
|
||||
MP4GetTrackBytesProperty(fileHandle ,_trackId, "tkhd.matrix", &val, &size);
|
||||
memcpy(nval, val, size);
|
||||
ptr32[6] = CFSwapInt32HostToBig(offsetX * 0x10000);
|
||||
ptr32[7] = CFSwapInt32HostToBig(offsetY * 0x10000);
|
||||
ptr32[6] = CFSwapInt32HostToBig(_offsetX * 0x10000);
|
||||
ptr32[7] = CFSwapInt32HostToBig(_offsetY * 0x10000);
|
||||
MP4SetTrackBytesProperty(fileHandle, _trackId, "tkhd.matrix", nval, size);
|
||||
|
||||
free(val);
|
||||
|
||||
if (_updatedProperty[@"hSpacing"] || _updatedProperty[@"vSpacing"]) {
|
||||
if (hSpacing >= 1 && vSpacing >= 1) {
|
||||
if (self.updatedProperty[@"hSpacing"] || self.updatedProperty[@"vSpacing"]) {
|
||||
if (_hSpacing >= 1 && _vSpacing >= 1) {
|
||||
if (MP4HaveTrackAtom(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp")) {
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", hSpacing);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", vSpacing);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", _hSpacing);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", _vSpacing);
|
||||
}
|
||||
else {
|
||||
MP4AddPixelAspectRatio(fileHandle, _trackId, (uint32_t)hSpacing, (uint32_t)vSpacing);
|
||||
MP4AddPixelAspectRatio(fileHandle, _trackId, (uint32_t)_hSpacing, (uint32_t)_vSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cleanApertureWidthN >= 1 && cleanApertureHeightN >= 1) {
|
||||
if (_cleanApertureWidthN >= 1 && _cleanApertureHeightN >= 1) {
|
||||
if (MP4HaveTrackAtom(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap")) {
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", cleanApertureWidthN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", cleanApertureWidthD);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", _cleanApertureWidthN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", _cleanApertureWidthD);
|
||||
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", cleanApertureHeightN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", cleanApertureHeightD);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", _cleanApertureHeightN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", _cleanApertureHeightD);
|
||||
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", horizOffN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", horizOffD);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", _horizOffN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", _horizOffD);
|
||||
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", vertOffN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", vertOffD);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", _vertOffN);
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", _vertOffD);
|
||||
}
|
||||
else
|
||||
MP4AddCleanAperture(fileHandle, _trackId, cleanApertureWidthN, cleanApertureWidthD, cleanApertureHeightN, cleanApertureHeightD,
|
||||
horizOffN, horizOffD, vertOffN, vertOffD);
|
||||
MP4AddCleanAperture(fileHandle, _trackId, _cleanApertureWidthN, _cleanApertureWidthD, _cleanApertureHeightN, _cleanApertureHeightD,
|
||||
_horizOffN, _horizOffD, _vertOffN, _vertOffD);
|
||||
}
|
||||
|
||||
if (_format == kMP42VideoCodecType_H264) {
|
||||
if (_updatedProperty[@"profile"]) {
|
||||
if (self.updatedProperty[@"profile"]) {
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*[0].avcC.AVCProfileIndication", _newProfile);
|
||||
_origProfile = _newProfile;
|
||||
}
|
||||
if (_updatedProperty[@"level"]) {
|
||||
if (self.updatedProperty[@"level"]) {
|
||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.*[0].avcC.AVCLevelIndication", _newLevel);
|
||||
_origLevel = _newLevel;
|
||||
}
|
||||
@@ -175,44 +174,28 @@
|
||||
return (_trackId > 0);
|
||||
}
|
||||
|
||||
@synthesize width;
|
||||
@synthesize height;
|
||||
|
||||
@synthesize trackWidth;
|
||||
@synthesize trackHeight;
|
||||
|
||||
|
||||
- (uint64_t)hSpacing {
|
||||
return hSpacing;
|
||||
return _hSpacing;
|
||||
}
|
||||
|
||||
- (void)setHSpacing:(uint64_t)newHSpacing
|
||||
{
|
||||
hSpacing = newHSpacing;
|
||||
_hSpacing = newHSpacing;
|
||||
_isEdited = YES;
|
||||
_updatedProperty[@"hSpacing"] = @YES;
|
||||
self.updatedProperty[@"hSpacing"] = @YES;
|
||||
}
|
||||
|
||||
- (uint64_t)vSpacing {
|
||||
return vSpacing;
|
||||
return _vSpacing;
|
||||
}
|
||||
|
||||
- (void)setVSpacing:(uint64_t)newVSpacing
|
||||
{
|
||||
vSpacing = newVSpacing;
|
||||
_vSpacing = newVSpacing;
|
||||
_isEdited = YES;
|
||||
_updatedProperty[@"vSpacing"] = @YES;
|
||||
self.updatedProperty[@"vSpacing"] = @YES;
|
||||
}
|
||||
|
||||
@synthesize offsetX;
|
||||
@synthesize offsetY;
|
||||
|
||||
@synthesize cleanApertureHeightD, cleanApertureHeightN, cleanApertureWidthD, cleanApertureWidthN;
|
||||
@synthesize horizOffD, horizOffN, vertOffD, vertOffN;
|
||||
|
||||
@synthesize origProfile = _origProfile;
|
||||
@synthesize origLevel = _origLevel;
|
||||
|
||||
- (uint8_t)newProfile {
|
||||
return _newProfile;
|
||||
}
|
||||
@@ -223,10 +206,10 @@
|
||||
_isEdited = YES;
|
||||
|
||||
if (_newProfile == _origProfile) {
|
||||
_updatedProperty[@"profile"] = @NO;
|
||||
self.updatedProperty[@"profile"] = @NO;
|
||||
}
|
||||
else {
|
||||
_updatedProperty[@"profile"] = @YES;
|
||||
self.updatedProperty[@"profile"] = @YES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,13 +223,49 @@
|
||||
_isEdited = YES;
|
||||
|
||||
if (_newLevel == _origLevel) {
|
||||
_updatedProperty[@"level"] = @NO;
|
||||
self.updatedProperty[@"level"] = @NO;
|
||||
}
|
||||
else {
|
||||
_updatedProperty[@"level"] = @YES;
|
||||
self.updatedProperty[@"level"] = @YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - NSCopying
|
||||
|
||||
- (instancetype)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
MP42VideoTrack *copy = [super copyWithZone:zone];
|
||||
|
||||
if (copy) {
|
||||
copy->_width = _width;
|
||||
copy->_height = _height;
|
||||
copy->_trackWidth = _trackWidth;
|
||||
copy->_trackHeight = _trackHeight;
|
||||
|
||||
copy->_hSpacing = _hSpacing;
|
||||
copy->_vSpacing = _vSpacing;
|
||||
|
||||
copy->_cleanApertureWidthN = _cleanApertureWidthN;
|
||||
copy->_cleanApertureWidthD = _cleanApertureWidthD;
|
||||
copy->_cleanApertureHeightN = _cleanApertureHeightN;
|
||||
copy->_cleanApertureHeightD = _cleanApertureHeightD;
|
||||
copy->_horizOffN = _horizOffN;
|
||||
copy->_horizOffD = _horizOffD;
|
||||
copy->_vertOffN = _vertOffN;
|
||||
copy->_vertOffD = _vertOffD;
|
||||
|
||||
copy->_offsetX = _offsetX;
|
||||
copy->_offsetY = _offsetY;
|
||||
|
||||
copy->_origLevel = _origLevel;
|
||||
copy->_origProfile = _origProfile;
|
||||
copy->_newProfile = _newProfile;
|
||||
copy->_newLevel = _newLevel;
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
#pragma mark - NSSecureCoding
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
@@ -255,17 +274,17 @@
|
||||
|
||||
[coder encodeInt:1 forKey:@"MP42VideoTrackVersion"];
|
||||
|
||||
[coder encodeInt64:width forKey:@"width"];
|
||||
[coder encodeInt64:height forKey:@"height"];
|
||||
[coder encodeInt64:_width forKey:@"width"];
|
||||
[coder encodeInt64:_height forKey:@"height"];
|
||||
|
||||
[coder encodeFloat:trackWidth forKey:@"trackWidth"];
|
||||
[coder encodeFloat:trackHeight forKey:@"trackHeight"];
|
||||
[coder encodeFloat:_trackWidth forKey:@"trackWidth"];
|
||||
[coder encodeFloat:_trackHeight forKey:@"trackHeight"];
|
||||
|
||||
[coder encodeInt64:hSpacing forKey:@"hSpacing"];
|
||||
[coder encodeInt64:vSpacing forKey:@"vSpacing"];
|
||||
[coder encodeInt64:_hSpacing forKey:@"hSpacing"];
|
||||
[coder encodeInt64:_vSpacing forKey:@"vSpacing"];
|
||||
|
||||
[coder encodeInt32:offsetX forKey:@"offsetX"];
|
||||
[coder encodeInt32:offsetY forKey:@"offsetY"];
|
||||
[coder encodeInt32:_offsetX forKey:@"offsetX"];
|
||||
[coder encodeInt32:_offsetY forKey:@"offsetY"];
|
||||
|
||||
[coder encodeInt:_origProfile forKey:@"origProfile"];
|
||||
[coder encodeInt:_origLevel forKey:@"origLevel"];
|
||||
@@ -278,17 +297,17 @@
|
||||
{
|
||||
self = [super initWithCoder:decoder];
|
||||
|
||||
width = [decoder decodeInt64ForKey:@"width"];
|
||||
height = [decoder decodeInt64ForKey:@"height"];
|
||||
_width = [decoder decodeInt64ForKey:@"width"];
|
||||
_height = [decoder decodeInt64ForKey:@"height"];
|
||||
|
||||
trackWidth = [decoder decodeFloatForKey:@"trackWidth"];
|
||||
trackHeight = [decoder decodeFloatForKey:@"trackHeight"];
|
||||
_trackWidth = [decoder decodeFloatForKey:@"trackWidth"];
|
||||
_trackHeight = [decoder decodeFloatForKey:@"trackHeight"];
|
||||
|
||||
hSpacing = [decoder decodeInt64ForKey:@"hSpacing"];
|
||||
vSpacing = [decoder decodeInt64ForKey:@"vSpacing"];
|
||||
_hSpacing = [decoder decodeInt64ForKey:@"hSpacing"];
|
||||
_vSpacing = [decoder decodeInt64ForKey:@"vSpacing"];
|
||||
|
||||
offsetX = [decoder decodeInt32ForKey:@"offsetX"];
|
||||
offsetY = [decoder decodeInt32ForKey:@"offsetY"];
|
||||
_offsetX = [decoder decodeInt32ForKey:@"offsetX"];
|
||||
_offsetY = [decoder decodeInt32ForKey:@"offsetY"];
|
||||
|
||||
_origProfile = [decoder decodeIntForKey:@"origProfile"];
|
||||
_origLevel = [decoder decodeIntForKey:@"origLevel"];
|
||||
@@ -300,7 +319,7 @@
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [[super description] stringByAppendingFormat:@", %lld x %lld", width, height];
|
||||
return [[super description] stringByAppendingFormat:@", %lld x %lld", _width, _height];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user