Skip to content
This repository was archived by the owner on Mar 26, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions api/iOS/VCSimpleSession.mm
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,10 @@ - (void) addEncodersAndPacketizers
self.fps,
self.bitrate);
}
m_audioMixer->setOutput(m_aacEncoder);
m_videoSplit->setOutput(m_h264Encoder);

if (m_aacEncoder != nullptr && m_h264Encoder != nullptr) {
m_audioMixer->setOutput(m_aacEncoder);
m_videoSplit->setOutput(m_h264Encoder);
}
}
{
m_aacSplit = std::make_shared<videocore::Split>();
Expand Down Expand Up @@ -853,6 +854,7 @@ - (void) addEncodersAndPacketizers


}
/*
- (void) addPixelBufferSource: (UIImage*) image
withRect:(CGRect)rect {
CGImageRef ref = [image CGImage];
Expand Down Expand Up @@ -890,7 +892,54 @@ - (void) addPixelBufferSource: (UIImage*) image

free(rawData);

}*/

- (void) addPixelBufferSource: (UIImage*) image
withRect:(CGRect)rect {
CGImageRef ref = [image CGImage];

std::shared_ptr<videocore::Apple::PixelBufferSource> temp_pixelBufferSource = m_pixelBufferSource;


m_pixelBufferSource = std::make_shared<videocore::Apple::PixelBufferSource>(CGImageGetWidth(ref),
CGImageGetHeight(ref),
'BGRA');
NSUInteger width = CGImageGetWidth(ref);
NSUInteger height = CGImageGetHeight(ref);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), ref);
CGContextRelease(context);

m_pbAspect = std::make_shared<videocore::AspectTransform>(rect.size.width,rect.size.height,videocore::AspectTransform::kAspectFit);

m_pbPosition = std::make_shared<videocore::PositionTransform>(rect.origin.x, rect.origin.y,
rect.size.width, rect.size.height,
self.videoSize.width, self.videoSize.height
);
m_pixelBufferSource->setOutput(m_pbAspect);
m_pbAspect->setOutput(m_pbPosition);
m_pbPosition->setOutput(m_videoMixer);
m_videoMixer->registerSource(m_pixelBufferSource);
m_pixelBufferSource->pushPixelBuffer(rawData, width * height * 4);

free(rawData);


if(temp_pixelBufferSource){
m_videoMixer->unregisterSource(temp_pixelBufferSource);
}

}

- (NSString *) applicationDocumentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
Expand Down