예제 #1
0
// ImageCodecPreflight
// 		The base image decompressor gets additional information about the capabilities of your image
// decompressor component by calling ImageCodecPreflight. The base image decompressor uses this
// information when responding to a call to the ImageCodecPredecompress function,
// which the ICM makes before decompressing an image. You are required only to provide values for
// the wantedDestinationPixelSize and wantedDestinationPixelTypes fields and can also modify other
// fields if necessary.
pascal ComponentResult TextSubCodecPreflight(TextSubGlobals glob, CodecDecompressParams *p)
{
	CodecCapabilities *capabilities = p->capabilities;
	OSTypePtr         formats = *glob->wantedDestinationPixelTypeH;

	// Fill in formats for wantedDestinationPixelTypeH
	// Terminate with an OSType value 0  - see IceFloe #7
	// http://developer.apple.com/quicktime/icefloe/dispatch007.html
    
    // we want ARGB because Quartz can use it easily
    *formats++	= k32RGBAPixelFormat;
	*formats++	= k32ARGBPixelFormat;
	
	// Specify the minimum image band height supported by the component
	// bandInc specifies a common factor of supported image band heights - 
	// if your component supports only image bands that are an even
    // multiple of some number of pixels high report this common factor in bandInc
	capabilities->bandMin = (**p->imageDescription).height;
	capabilities->bandInc = capabilities->bandMin;

	// Indicate the wanted destination using the wantedDestinationPixelTypeH previously set up
	capabilities->wantedPixelSize  = 0; 	
    
	p->wantedDestinationPixelTypes = glob->wantedDestinationPixelTypeH;

	// Specify the number of pixels the image must be extended in width and height if
	// the component cannot accommodate the image at its given width and height
	capabilities->extendWidth = 0;
	capabilities->extendHeight = 0;
	
	capabilities->flags |= codecCanAsync | codecCanAsyncWhen | codecCanScale;
	capabilities->flags2 |= codecDrawsHigherQualityScaled;    
	
	if (!glob->ssa) {
		Ptr ssaheader = NULL;
		size_t ssaheadersize = 0;
		
		if (!glob->colorSpace)
			glob->colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
		
		if ((**p->imageDescription).cType == kSubFormatSSA) {
			long count;
			glob->translateSRT = false;
			
			CountImageDescriptionExtensionType(p->imageDescription,kSubFormatSSA,&count);
			if (count == 1) {
				Handle ssahand;
				GetImageDescriptionExtension(p->imageDescription,&ssahand,kSubFormatSSA,1);
				
				ssaheader = *ssahand;
				ssaheadersize = GetHandleSize(ssahand);				
			} 
		} 
		
		glob->ssa = SubRendererCreate((**p->imageDescription).cType == kSubFormatSSA, ssaheader,
									  ssaheadersize, (**p->imageDescription).width,(**p->imageDescription).height);
	}
	
	return noErr;
}
예제 #2
0
ComponentResult XMRTPH264Packetizer_PreflightMedia(XMRTPH264PacketizerGlobals globals, OSType inMediaType,
                                                   SampleDescriptionHandle inSampleDescription)
{
  ComponentResult err = noErr;
	
  Handle avccExtension = NULL;
  err = GetImageDescriptionExtension((ImageDescriptionHandle)inSampleDescription,
                                     &avccExtension,
                                     FOUR_CHAR_CODE('avcC'),
                                     1);
  if (err != noErr) {
    printf("GetImageDescriptionExtension failed");
  }
	
  UInt8 *data = (UInt8 *)*avccExtension;
	
  UInt16 *spsLengthData = (UInt16 *)&(data[6]);
  UInt16 spsAtomLength = ntohs(spsLengthData[0]);
	
  UInt32 ppsAtomLengthIndex = 9 + spsAtomLength;
	
  UInt16 *ppsLengthData = (UInt16 *)&(data[ppsAtomLengthIndex]);
  UInt16 ppsAtomLength = ntohs(ppsLengthData[0]);
	
  globals->spsAtomData = malloc(spsAtomLength * sizeof(UInt8));
  globals->ppsAtomData = malloc(ppsAtomLength * sizeof(UInt8));
	
  UInt8 *src = &(data[8]);
  memcpy(globals->spsAtomData, src, spsAtomLength);
  globals->spsAtomLength = spsAtomLength;
	
  src = &(data[ppsAtomLengthIndex + 2]);
  memcpy(globals->ppsAtomData, src, ppsAtomLength);
  globals->ppsAtomLength = ppsAtomLength;
	
  /*printf("SPS: \n");
	for (unsigned i = 0; i < spsAtomLength; i++) {
    printf("%x ", globals->spsAtomData[i]);
  }
  printf("\n");*/
  /*
  printf("PPS: \n");
  for (i = 0; i < ppsAtomLength; i++) {
    printf("%x ", globals->ppsAtomData[i]);
  }
  printf("\n");*/
	
  DisposeHandle(avccExtension);
  return err;
}
예제 #3
0
OSErr init_theora_decoder(Theora_Globals glob, CodecDecompressParams *p)
{
    OSErr err = noErr;
    Handle ext;
    //OggSerialNoAtom *atom;
    Byte *ptrheader, *mCookie, *cend;
    UInt32 mCookieSize;
    CookieAtomHeader *aheader;
    th_comment tc;
    ogg_packet header, header_tc, header_cb;

    if (glob->info_initialised) {
        dbg_printf("--:Theora:- Decoder already initialised, skipping...\n");
        return err;
    }

    err = GetImageDescriptionExtension(p->imageDescription, &ext, kSampleDescriptionExtensionTheora, 1);
    if (err != noErr) {
        dbg_printf("XXX GetImageDescriptionExtension() failed! ('%4.4s')\n", &(*p->imageDescription)->cType);
        err = codecBadDataErr;
        return err;
    }

    mCookie = (UInt8 *) *ext;
    mCookieSize = GetHandleSize(ext);

    ptrheader = mCookie;
    cend = mCookie + mCookieSize;

    aheader = (CookieAtomHeader*)ptrheader;


    header.bytes = header_tc.bytes = header_cb.bytes = 0;

    while (ptrheader < cend) {
        aheader = (CookieAtomHeader *) ptrheader;
        ptrheader += EndianU32_BtoN(aheader->size);
        if (ptrheader > cend || EndianU32_BtoN(aheader->size) <= 0)
            break;

        switch(EndianS32_BtoN(aheader->type)) {
        case kCookieTypeTheoraHeader:
            header.b_o_s = 1;
            header.e_o_s = 0;
            header.granulepos = 0;
            header.packetno = 0;
            header.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long);
            header.packet = aheader->data;
            break;

        case kCookieTypeTheoraComments:
            header_tc.b_o_s = 0;
            header_tc.e_o_s = 0;
            header_tc.granulepos = 0;
            header_tc.packetno = 1;
            header_tc.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long);
            header_tc.packet = aheader->data;
            break;

        case kCookieTypeTheoraCodebooks:
            header_cb.b_o_s = 0;
            header_cb.e_o_s = 0;
            header_cb.granulepos = 0;
            header_cb.packetno = 2;
            header_cb.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long);
            header_cb.packet = aheader->data;
            break;

        default:
            break;
        }
    }

    err = codecBadDataErr;

    if (header.bytes == 0 || header_tc.bytes == 0 || header_cb.bytes == 0)
        return err;

    th_info_init(&glob->ti);
    th_comment_init(&tc);
    glob->ts = NULL;

    if (th_decode_headerin(&glob->ti, &tc, &glob->ts, &header) < 0) {

        if (glob->ts != NULL)
            th_setup_free (glob->ts);
        th_comment_clear(&tc);
        th_info_clear(&glob->ti);

        return err;
    }

    th_decode_headerin(&glob->ti, &tc, &glob->ts, &header_tc);
    th_decode_headerin(&glob->ti, &tc, &glob->ts, &header_cb);

    err = noErr;

    th_comment_clear(&tc);

    dbg_printf("--:Theora:- OK, managed to initialize the decoder somehow...\n");
    glob->info_initialised = true;

    return err;
}