Exemple #1
0
int theora_encode_comment(theora_comment *_tc,ogg_packet *_op){
  oggpack_buffer  opb;
  void           *buf;
  int             packet_state;
  int             ret;
  packet_state=OC_PACKET_COMMENT_HDR;
  oggpackB_writeinit(&opb);
  ret=oc_state_flushheader(NULL,&packet_state,&opb,NULL,NULL,
   th_version_string(),(th_comment *)_tc,_op);
  if(ret>=0){
    /*The oggpack_buffer's lifetime ends with this function, so we have to
       copy out the packet contents.
      Presumably the application knows it is supposed to free this.
      This part works nothing like the Vorbis API, and the documentation on it
       has been wrong for some time, claiming libtheora owned the memory.*/
    buf=_ogg_malloc(_op->bytes);
    if(buf==NULL){
      _op->packet=NULL;
      ret=TH_EFAULT;
    }
    else{
      memcpy(buf,_op->packet,_op->bytes);
      _op->packet=buf;
      ret=0;
    }
  }
  oggpack_writeclear(&opb);
  return ret;
}
Exemple #2
0
	Manager::Manager() : defaultPrecachedFramesCount(8), workMutex(new Mutex()), audioInterfaceFactory(NULL)
	{
		std::string message = "Initializing Theoraplayer Video Playback Library (" + this->getVersionString() + ")\n";
#ifdef _USE_THEORA
		message += "  - libtheora version: " + std::string(th_version_string()) + "\n" +
			"  - libvorbis version: " + std::string(vorbis_version_string()) + "\n";
#endif
#ifdef _ANDROID
		uint64_t features = libtheoraplayer_android_getCpuFeaturesExt();
		char s[128] = { 0 };
		sprintf(s, "  - Android: CPU Features: %u\n", (unsigned int)features);
		message += s;
		if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0)
		{
			message += "  - Android: NEON features NOT SUPPORTED by CPU\n";
		}
		else
		{
			message += "  - Android: Detected NEON CPU features\n";
		}
#endif
		log(message + "------------------------------------");
		// for CPU based yuv2rgb decoding
		initYUVConversionModule();
	}
/* Print the library's own version string
   This is generally the same at the vendor string embedded
   in encoded files. */
int print_version_string(void)
{
    const char *version = th_version_string();

    if (version == NULL) {
      fprintf(stderr, "Error querying libtheora version string.\n");
      return -1;
    }

    fprintf(stdout, "Version: %s\n", version);

    return 0;
}
Exemple #4
0
TheoraVideoManager::TheoraVideoManager(int num_worker_threads) :
    mDefaultNumPrecachedFrames(8)
{
    if (num_worker_threads < 1) throw TheoraGenericException("Unable to create TheoraVideoManager, at least one worker thread is reqired");

    g_ManagerSingleton = this;

    std::string msg = "Initializing Theora Playback Library (" + getVersionString() + ")\n";
#ifdef __THEORA
    msg += "  - libtheora version: " + std::string(th_version_string()) + "\n" +
           "  - libvorbis version: " +  std::string(vorbis_version_string()) + "\n";
#endif
#ifdef _ANDROID
    uint64_t features = android_getCpuFeaturesExt();
    char s[128];
    sprintf(s, "  - Android: CPU Features: %u\n", (unsigned int) features);
    msg += s;
    if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0)
        msg += "  - Android: NEON features NOT SUPPORTED by CPU\n";
    else
        msg += "  - Android: Detected NEON CPU features\n";
#endif

#ifdef __AVFOUNDATION
    msg += "  - using Apple AVFoundation classes.\n";
#endif
#ifdef __FFMPEG
    msg += "  - using FFmpeg library.\n";
#endif

    logMessage(msg + "------------------------------------");
    mAudioFactory = NULL;
    mWorkMutex = new TheoraMutex();

    // for CPU based yuv2rgb decoding
    initYUVConversionModule();

    createWorkerThreads(num_worker_threads);
}
Exemple #5
0
krad_theora_encoder_t *krad_theora_encoder_create (int width, int height,
        int fps_numerator,
        int fps_denominator,
        int color_depth,
        int quality) {

    krad_theora_encoder_t *krad_theora;

    krad_theora = calloc (1, sizeof(krad_theora_encoder_t));

    krad_theora->width = width;
    krad_theora->height = height;
    krad_theora->quality = quality;
    krad_theora->color_depth = color_depth;

    th_info_init (&krad_theora->info);
    th_comment_init (&krad_theora->comment);

    krad_theora->info.frame_width = krad_theora->width;
    if (krad_theora->width % 16) {
        krad_theora->info.frame_width += 16 - (krad_theora->width % 16);
    }
    krad_theora->info.frame_height = krad_theora->height;
    if (krad_theora->height % 16) {
        krad_theora->info.frame_height += 16 - (krad_theora->height % 16);
    }
    krad_theora->info.pic_width = krad_theora->width;
    krad_theora->info.pic_height = krad_theora->height;
    krad_theora->info.pic_x = 0;
    krad_theora->info.pic_y = 0;
    krad_theora->info.aspect_denominator = 1;
    krad_theora->info.aspect_numerator = 1;
    krad_theora->info.target_bitrate = 0;
    krad_theora->info.quality = krad_theora->quality;
    if (krad_theora->color_depth == PIX_FMT_YUV420P) {
        krad_theora->info.pixel_fmt = TH_PF_420;
    }
    if (krad_theora->color_depth == PIX_FMT_YUV422P) {
        krad_theora->info.pixel_fmt = TH_PF_422;
    }
    if (krad_theora->color_depth == PIX_FMT_YUV444P) {
        krad_theora->info.pixel_fmt = TH_PF_444;
    }
    krad_theora->keyframe_shift = krad_theora->info.keyframe_granule_shift;

    printk ("Loading Theora encoder version %s", th_version_string());
    printk ("Theora keyframe shift %d", krad_theora->keyframe_shift);

    krad_theora->info.fps_numerator = fps_numerator;
    krad_theora->info.fps_denominator = fps_denominator;
    //krad_theora->keyframe_distance = 30;

    krad_theora->encoder = th_encode_alloc (&krad_theora->info);

    //th_encode_ctl (krad_theora->encoder,
    //TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
    // &krad_theora->keyframe_distance, sizeof(int));
    //printk ("Theora keyframe max distance %u\n",
    //  krad_theora->keyframe_distance);

    /*
    if (strstr(krad_system_cpu_type(), "x86") == NULL) {
      //FOR ARM Realtime
      th_encode_ctl (krad_theora->encoder,
                     TH_ENCCTL_GET_SPLEVEL_MAX,
                     &krad_theora->speed,
                     sizeof(int));
      printk ("Theora encoder speed: %d quality: %d",
              krad_theora->speed, krad_theora->quality);
      th_encode_ctl (krad_theora->encoder, TH_ENCCTL_SET_SPLEVEL,
                     &krad_theora->speed, sizeof(int));
    } else {
      //FOR x86 Realtime
      th_encode_ctl (krad_theora->encoder,
                     TH_ENCCTL_GET_SPLEVEL_MAX,
                     &krad_theora->speed, sizeof(int));
      if ((krad_theora->width <= 1280) && (krad_theora->height <= 720)) {
        krad_theora->speed -= 1;
      }
      printk ("Theora encoder speed: %d quality: %d",
              krad_theora->speed, krad_theora->quality);
      th_encode_ctl (krad_theora->encoder,
                     TH_ENCCTL_SET_SPLEVEL,
                     &krad_theora->speed, sizeof(int));
    }
    */
    /*
      while (th_encode_flushheader ( krad_theora->encoder,
                                     &krad_theora->comment,
                                     &krad_theora->packet) > 0) {

        krad_theora->header_combined_size += krad_theora->packet.bytes;
        krad_theora->header[krad_theora->header_count] =
          malloc (krad_theora->packet.bytes);
        memcpy (krad_theora->header[krad_theora->header_count],
                krad_theora->packet.packet,
                krad_theora->packet.bytes);
        krad_theora->header_len[krad_theora->header_count] =
          krad_theora->packet.bytes;
        krad_theora->header_count++;

        //printk ("krad_theora_encoder_create th_encode_flushheader got
        // header packet %"PRIi64" which is %ld bytes\n",
        //    krad_theora->packet.packetno, krad_theora->packet.bytes);
      }

      //printk ("krad_theora_encoder_create Got %d header packets\n",
      //      krad_theora->header_count);

      krad_theora->header_combined = calloc (1, krad_theora->header_combined_size + 10);

      krad_theora->header_combined[0] = 0x02;
      krad_theora->header_combined_pos++;

      //printk ("main is %ld\n", vorbis->header_main.bytes);
      if (krad_theora->header_len[0] > 255) {
        failfast ("theora mainheader to long for code");
      }

      krad_theora->demented = krad_theora->header_len[0];
      krad_theora->header_combined[1] = (char)krad_theora->demented;
      krad_theora->header_combined_pos++;

      //printk ("comments is %ld\n", vorbis->header_comments.bytes);
      if (krad_theora->header_len[1] > 255) {
        failfast ("theora comments header to long for code");
      }

      krad_theora->demented = krad_theora->header_len[1];
      krad_theora->header_combined[2] = (char)krad_theora->demented;
      krad_theora->header_combined_pos++;

      krad_theora->header_combined_size += 3;

      memcpy (krad_theora->header_combined + krad_theora->header_combined_pos,
              krad_theora->header[0],
              krad_theora->header_len[0]);
      krad_theora->header_combined_pos += krad_theora->header_len[0];

      //printf("main is %ld bytes headerpos is  %d \n",
      //vorbis->header_main.bytes, vorbis->headerpos);

      memcpy (krad_theora->header_combined + krad_theora->header_combined_pos,
              krad_theora->header[1],
              krad_theora->header_len[1]);
      krad_theora->header_combined_pos += krad_theora->header_len[1];

      //printf("comments is %ld bytes headerpos is  %d \n",
      //vorbis->header_comments.bytes, vorbis->headerpos);

      memcpy (krad_theora->header_combined + krad_theora->header_combined_pos,
              krad_theora->header[2],
              krad_theora->header_len[2]);
      krad_theora->header_combined_pos += krad_theora->header_len[2];
      krad_theora->krad_codec_header.codec = THEORA;
      krad_theora->krad_codec_header.header[0] = krad_theora->header[0];
      krad_theora->krad_codec_header.header_size[0] = krad_theora->header_len[0];
      krad_theora->krad_codec_header.header[1] = krad_theora->header[1];
      krad_theora->krad_codec_header.header_size[1] = krad_theora->header_len[1];
      krad_theora->krad_codec_header.header[2] = krad_theora->header[2];
      krad_theora->krad_codec_header.header_size[2] = krad_theora->header_len[2];

      krad_theora->krad_codec_header.header_combined = krad_theora->header_combined;
      krad_theora->krad_codec_header.header_combined_size = krad_theora->header_combined_size;
      krad_theora->krad_codec_header.header_count = 3;

      krad_theora->ycbcr[0].stride =  krad_theora->info.frame_width;
      krad_theora->ycbcr[0].width =  krad_theora->info.frame_width;
      krad_theora->ycbcr[0].height =  krad_theora->info.frame_height;

      krad_theora->ycbcr[0].data = calloc(1, krad_theora->info.frame_width * krad_theora->info.frame_height);

      if (krad_theora->color_depth == PIX_FMT_YUV420P) {
        krad_theora->ycbcr[1].stride = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[1].width = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[1].height = krad_theora->info.frame_height / 2;
        krad_theora->ycbcr[2].stride = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[2].width = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[2].height = krad_theora->info.frame_height / 2;

        krad_theora->ycbcr[1].data = calloc(1, ((krad_theora->info.frame_width / 2) * (krad_theora->info.frame_height / 2)));
        krad_theora->ycbcr[2].data = calloc(1, ((krad_theora->info.frame_width / 2) * (krad_theora->info.frame_height / 2)));
      }
      if (krad_theora->color_depth == PIX_FMT_YUV422P) {
        krad_theora->ycbcr[1].stride = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[1].width =  krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[1].height =  krad_theora->info.frame_height;
        krad_theora->ycbcr[2].stride = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[2].width = krad_theora->info.frame_width / 2;
        krad_theora->ycbcr[2].height =  krad_theora->info.frame_height;

        krad_theora->ycbcr[1].data = calloc(1, ((krad_theora->info.frame_width / 2) * krad_theora->info.frame_height));
        krad_theora->ycbcr[2].data = calloc(1, ((krad_theora->info.frame_width / 2) * krad_theora->info.frame_height));

      }
      if (krad_theora->color_depth == PIX_FMT_YUV444P) {
        krad_theora->ycbcr[1].stride = krad_theora->info.frame_width;
        krad_theora->ycbcr[1].width = krad_theora->info.frame_width;
        krad_theora->ycbcr[1].height = krad_theora->info.frame_height;
        krad_theora->ycbcr[2].stride = krad_theora->info.frame_width;
        krad_theora->ycbcr[2].width = krad_theora->info.frame_width;
        krad_theora->ycbcr[2].height = krad_theora->info.frame_height;

        krad_theora->ycbcr[1].data = calloc(1, krad_theora->info.frame_width * krad_theora->info.frame_height);
        krad_theora->ycbcr[2].data = calloc(1, krad_theora->info.frame_width * krad_theora->info.frame_height);
      }
    */
    return krad_theora;

}
Exemple #6
0
const char *theora_version_string(void){
  return th_version_string();
}