Exemple #1
0
static int
noop_test_encode ()
{
  th_info ti;
  th_enc_ctx *te;

  INFO ("+ Initializing th_info struct");
  th_info_init (&ti);

  INFO ("+ Testing encoder context with empty th_info");
  te = th_encode_alloc(&ti);
  if (te != NULL)
    FAIL("td_encode_alloc accepted an unconfigured th_info");

  INFO ("+ Setting 16x16 image size");
  ti.frame_width = 16;
  ti.frame_height = 16;

  INFO ("+ Allocating encoder context");
  te = th_encode_alloc(&ti);
  if (te == NULL)
    FAIL("td_encode_alloc returned a null pointer");

  INFO ("+ Clearing th_info struct");
  th_info_clear (&ti);

  INFO ("+ Freeing encoder context");
  th_encode_free(te);

  return 0;
}
bool CHolly_Theora_Video::End()
{
	ProcessFrame( true );

	th_encode_free( m_Encoder );
	m_Encoder = NULL;

	FreeFrame();

	return true;
}
Exemple #3
0
static av_cold int encode_close(AVCodecContext* avc_context)
{
    TheoraContext *h = avc_context->priv_data;

    th_encode_free(h->t_state);
    av_freep(&h->stats);
    av_freep(&avc_context->stats_out);
    av_freep(&avc_context->extradata);
    avc_context->extradata_size = 0;

    return 0;
}
static void
theora_enc_reset (GstTheoraEnc * enc)
{
    ogg_uint32_t keyframe_force;
    int rate_flags;

    GST_OBJECT_LOCK (enc);
    enc->info.target_bitrate = enc->video_bitrate;
    enc->info.quality = enc->video_quality;
    enc->bitrate_changed = FALSE;
    enc->quality_changed = FALSE;
    GST_OBJECT_UNLOCK (enc);

    if (enc->encoder)
        th_encode_free (enc->encoder);
    enc->encoder = th_encode_alloc (&enc->info);
    /* We ensure this function cannot fail. */
    g_assert (enc->encoder != NULL);
    th_encode_ctl (enc->encoder, TH_ENCCTL_SET_SPLEVEL, &enc->speed_level,
                   sizeof (enc->speed_level));
    th_encode_ctl (enc->encoder, TH_ENCCTL_SET_VP3_COMPATIBLE,
                   &enc->vp3_compatible, sizeof (enc->vp3_compatible));

    rate_flags = 0;
    if (enc->drop_frames)
        rate_flags |= TH_RATECTL_DROP_FRAMES;
    if (enc->drop_frames)
        rate_flags |= TH_RATECTL_CAP_OVERFLOW;
    if (enc->drop_frames)
        rate_flags |= TH_RATECTL_CAP_UNDERFLOW;
    th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_FLAGS,
                   &rate_flags, sizeof (rate_flags));

    if (enc->rate_buffer) {
        th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_BUFFER,
                       &enc->rate_buffer, sizeof (enc->rate_buffer));
    } else {
        /* FIXME */
    }

    keyframe_force = enc->keyframe_auto ?
                     enc->keyframe_force : enc->keyframe_freq;
    th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
                   &keyframe_force, sizeof (keyframe_force));

    /* Get placeholder data */
    if (enc->multipass_cache_fd
            && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS)
        theora_enc_write_multipass_cache (enc, TRUE, FALSE);
}
Exemple #5
0
static void
theora_enc_finalize (GObject * object)
{
  GstTheoraEnc *enc = GST_THEORA_ENC (object);

  GST_DEBUG_OBJECT (enc, "Finalizing");
  if (enc->encoder)
    th_encode_free (enc->encoder);
  th_comment_clear (&enc->comment);
  th_info_clear (&enc->info);
  g_free (enc->multipass_cache_file);

  theora_enc_clear_multipass_cache (enc);

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
Exemple #6
0
void theoraenc_delete (TheoraEnc *enc) {

  if (!enc) return;
  
  if (enc->info) {
    th_info_clear (enc->info);
    free (enc->info);
  }
  if (enc->comment) {
    th_comment_clear (enc->comment);
    free (enc->comment);
  }
  if (enc->ctx) th_encode_free (enc->ctx);
  if (enc->postconv_buffer) free (enc->postconv_buffer);
  free (enc);
}
static char *
theora_enc_get_supported_formats (void)
{
    th_enc_ctx *encoder;
    th_info info;
    struct
    {
        th_pixel_fmt pixelformat;
        const char *fourcc;
    } formats[] = {
        {
            TH_PF_420, "I420"
        }, {
            TH_PF_422, "Y42B"
        }, {
            TH_PF_444, "Y444"
        }
    };
    GString *string = NULL;
    guint i;

    th_info_init (&info);
    info.frame_width = 16;
    info.frame_height = 16;
    info.fps_numerator = 25;
    info.fps_denominator = 1;
    for (i = 0; i < G_N_ELEMENTS (formats); i++) {
        info.pixel_fmt = formats[i].pixelformat;

        encoder = th_encode_alloc (&info);
        if (encoder == NULL)
            continue;

        GST_LOG ("format %s is supported", formats[i].fourcc);
        th_encode_free (encoder);

        if (string == NULL) {
            string = g_string_new (formats[i].fourcc);
        } else {
            g_string_append (string, ", ");
            g_string_append (string, formats[i].fourcc);
        }
    }
    th_info_clear (&info);

    return string == NULL ? NULL : g_string_free (string, FALSE);
}
int main(int argc, char **argv) {
    th_enc_ctx *ctx;

    /* print versioning */
    print_version_string();
    print_version();

    /* allocate a generic context for queries that require it */
    ctx = dummy_encode_ctx();
    if (ctx != NULL) {
        /* dump the speed level setting */
        print_speed_level(ctx);
        /* clean up */
        th_encode_free(ctx);
    }

    return 0;
}
static gboolean
theora_enc_stop (GstVideoEncoder * benc)
{
    GstTheoraEnc *enc;

    GST_DEBUG_OBJECT (benc, "stop: clearing theora state");
    enc = GST_THEORA_ENC (benc);

    if (enc->encoder) {
        th_encode_free (enc->encoder);
        enc->encoder = NULL;
    }
    th_comment_clear (&enc->comment);
    th_info_clear (&enc->info);

    enc->initialised = FALSE;

    return TRUE;
}
Exemple #10
0
static int close_theora(void * data)
  {
  int ret = 1;
  theora_t * theora;
  theora = data;
  
#ifdef THEORA_1_1
  if(theora->stats_file)
    fclose(theora->stats_file);
  if(theora->stats_buf)
    free(theora->stats_buf);
#endif
  
  th_comment_clear(&theora->tc);
  th_info_clear(&theora->ti);
  th_encode_free(theora->ts);
  free(theora);
  return ret;
  }
Exemple #11
0
void krad_theora_encoder_destroy (krad_theora_encoder_t *krad_theora) {

    while (krad_theora->header_count--) {
        //printf("krad_theora_encoder_destroy freeing header %d\n",
        // krad_theora->header_count);
        free (krad_theora->header[krad_theora->header_count]);
    }

    th_info_clear (&krad_theora->info);
    th_comment_clear (&krad_theora->comment);
    th_encode_free (krad_theora->encoder);
    free (krad_theora->header_combined);

    free (krad_theora->ycbcr[0].data);
    free (krad_theora->ycbcr[1].data);
    free (krad_theora->ycbcr[2].data);

    free (krad_theora);

}
static gboolean
theora_enc_stop (GstVideoEncoder * benc)
{
  GstTheoraEnc *enc;

  GST_DEBUG_OBJECT (benc, "stop: clearing theora state");
  enc = GST_THEORA_ENC (benc);

  if (enc->encoder)
    th_encode_free (enc->encoder);
  enc->encoder = NULL;
  th_comment_clear (&enc->comment);
  th_info_clear (&enc->info);

  if (enc->input_state)
    gst_video_codec_state_unref (enc->input_state);
  enc->input_state = NULL;

  /* Everything else is handled in reset() */
  theora_enc_clear_multipass_cache (enc);

  return TRUE;
}
Exemple #13
0
void
gobee_theora_resize(int w, int h, int _stride, int sock, struct sockaddr *addr,
    int addrlen)
{
  time_t stamp = time(NULL);

  th_info_init(&tinfo);
  th_comment_init(&tcmnt);

  tinfo.frame_width = w;
  tinfo.frame_height = h;
  tinfo.pic_width = w;
  tinfo.pic_height = h;
  tinfo.pic_y = 0;
  tinfo.pic_x = 0;
  tinfo.fps_numerator = 30;
  tinfo.fps_denominator = 1;
  tinfo.aspect_denominator = 1;
  tinfo.aspect_numerator = 1;
  tinfo.target_bitrate = 200000;
  tinfo.quality = 12;
  tinfo.colorspace = TH_CS_ITU_REC_470BG; //TH_CS_UNSPECIFIED;
  tinfo.pixel_fmt = TH_PF_420;
  tinfo.keyframe_granule_shift = 100;
  tcmnt.vendor = "qqq";

  // recreate encoder
  if (tctx)
    th_encode_free(tctx);
  tctx = th_encode_alloc(&tinfo);

  __gobee_yuv_resize(&s_ycbcr, w, h);
  printf("sending...\n");
  __gobee_theora_send_headers(sock, addr, addrlen, stamp);
  printf("sent...\n");

}
Exemple #14
0
/*
 * End recording (called in a thread)
 */
void
MediaRecorder::EndRecordingThread(void *data)
{
    nsresult rv;
    PRUint32 wr;
    MediaRecorder *mr = static_cast<MediaRecorder*>(data);
    
    if (mr->v_rec) {
        rv = mr->vState->backend->StopRecording();
        if (NS_FAILED(rv)) {
            NS_DispatchToMainThread(new MediaCallback(
                mr->observer, "error", "could not stop video recording"
            ));
            return;
        }
    }

    if (mr->a_rec) {
        rv = mr->aState->backend->Stop();
        if (NS_FAILED(rv)) {
            NS_DispatchToMainThread(new MediaCallback(
                mr->observer, "error", "could not stop audio recording"
            ));
            return;
        }
    }

    /* Wait for encoder to finish */
    if (mr->v_rec) {
        mr->v_stp = PR_TRUE;
        mr->vState->vPipeOut->Close();
    }
    if (mr->a_rec) {
        mr->a_stp = PR_TRUE;
        mr->aState->aPipeOut->Close();
    }

    PR_JoinThread(mr->thread);

    if (mr->v_rec) {
        mr->vState->vPipeIn->Close();
        th_encode_free(mr->vState->th);

        /* Video trailer */
        if (ogg_stream_flush(&mr->vState->os, &mr->vState->og)) {
            rv = mr->WriteData(
                mr->vState->og.header, mr->vState->og.header_len, &wr
            );
            rv = mr->WriteData(
                mr->vState->og.body, mr->vState->og.body_len, &wr
            );
        }

        ogg_stream_clear(&mr->vState->os);
        mr->v_rec = PR_FALSE;
    }

    if (mr->a_rec) {
        mr->aState->aPipeIn->Close();

        /* Audio trailer */
        vorbis_analysis_wrote(&mr->aState->vd, 0);
        mr->WriteAudio();

        vorbis_block_clear(&mr->aState->vb);
        vorbis_dsp_clear(&mr->aState->vd);
        vorbis_comment_clear(&mr->aState->vc);
        vorbis_info_clear(&mr->aState->vi);
        ogg_stream_clear(&mr->aState->os);
        mr->a_rec = PR_FALSE;
    }

    /* GG */
    mr->pipeStream->Close();
    NS_DispatchToMainThread(new MediaCallback(
        mr->observer, "record-ended", ""
    ));
    return;
}
Exemple #15
0
static void
gst_theora_enc_class_init (GstTheoraEncClass * klass)
{
  GObjectClass *gobject_class = (GObjectClass *) klass;
  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);

  /* query runtime encoder properties */
  th_enc_ctx *th_ctx;
  int default_speed_level = THEORA_DEF_SPEEDLEVEL;
  int max_speed_level = default_speed_level;

  GST_DEBUG_CATEGORY_INIT (theoraenc_debug, "theoraenc", 0, "Theora encoder");

  th_ctx = dummy_encode_ctx ();
  if (th_ctx) {
    if (!check_speed_level (th_ctx, &default_speed_level, &max_speed_level))
      GST_WARNING
          ("Failed to determine settings for the speed-level property.");
    th_encode_free (th_ctx);
  }

  gobject_class->set_property = theora_enc_set_property;
  gobject_class->get_property = theora_enc_get_property;
  gobject_class->finalize = theora_enc_finalize;

  g_object_class_install_property (gobject_class, PROP_CENTER,
      g_param_spec_boolean ("center", "Center",
          "ignored and kept for API compat only", TRUE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_BORDER,
      g_param_spec_enum ("border", "Border",
          "ignored and kept for API compat only",
          GST_TYPE_BORDER_MODE, BORDER_BLACK,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  /* general encoding stream options */
  g_object_class_install_property (gobject_class, PROP_BITRATE,
      g_param_spec_int ("bitrate", "Bitrate", "Compressed video bitrate (kbps)",
          0, (1 << 24) - 1, THEORA_DEF_BITRATE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
          GST_PARAM_MUTABLE_PLAYING));
  g_object_class_install_property (gobject_class, PROP_QUALITY,
      g_param_spec_int ("quality", "Quality", "Video quality", 0, 63,
          THEORA_DEF_QUALITY,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
          GST_PARAM_MUTABLE_PLAYING));
  g_object_class_install_property (gobject_class, PROP_QUICK,
      g_param_spec_boolean ("quick", "Quick",
          "ignored and kept for API compat only", TRUE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_KEYFRAME_AUTO,
      g_param_spec_boolean ("keyframe-auto", "Keyframe Auto",
          "Automatic keyframe detection", THEORA_DEF_KEYFRAME_AUTO,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_KEYFRAME_FREQ,
      g_param_spec_int ("keyframe-freq", "Keyframe frequency",
          "Keyframe frequency", 1, 32768, THEORA_DEF_KEYFRAME_FREQ,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_KEYFRAME_FREQ_FORCE,
      g_param_spec_int ("keyframe-force", "Keyframe force",
          "Force keyframe every N frames", 1, 32768,
          THEORA_DEF_KEYFRAME_FREQ_FORCE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_KEYFRAME_THRESHOLD,
      g_param_spec_int ("keyframe-threshold", "Keyframe threshold",
          "ignored and kept for API compat only", 0, 32768, 80,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_KEYFRAME_MINDISTANCE,
      g_param_spec_int ("keyframe-mindistance", "Keyframe mindistance",
          "ignored and kept for API compat only", 1, 32768, 8,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_NOISE_SENSITIVITY,
      g_param_spec_int ("noise-sensitivity", "Noise sensitivity",
          "ignored and kept for API compat only", 0, 32768, 1,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_SHARPNESS,
      g_param_spec_int ("sharpness", "Sharpness",
          "ignored and kept for API compat only", 0, 2, 0,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_SPEEDLEVEL,
      g_param_spec_int ("speed-level", "Speed level",
          "Controls the amount of analysis performed when encoding."
          " Higher values trade compression quality for speed."
          " This property requires libtheora version >= 1.0"
          ", and the maximum value may vary based on encoder version.",
          0, max_speed_level, default_speed_level,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
          G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_VP3_COMPATIBLE,
      g_param_spec_boolean ("vp3-compatible", "VP3 Compatible",
          "Disables non-VP3 compatible features",
          THEORA_DEF_VP3_COMPATIBLE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_DROP_FRAMES,
      g_param_spec_boolean ("drop-frames", "VP3 Compatible",
          "Allow or disallow frame dropping",
          THEORA_DEF_DROP_FRAMES,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_CAP_OVERFLOW,
      g_param_spec_boolean ("cap-overflow", "VP3 Compatible",
          "Enable capping of bit reservoir overflows",
          THEORA_DEF_CAP_OVERFLOW,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_CAP_UNDERFLOW,
      g_param_spec_boolean ("cap-underflow", "VP3 Compatible",
          "Enable capping of bit reservoir underflows",
          THEORA_DEF_CAP_UNDERFLOW,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_RATE_BUFFER,
      g_param_spec_int ("rate-buffer", "Rate Control Buffer",
          "Sets the size of the rate control buffer, in units of frames.  "
          "The default value of 0 instructs the encoder to automatically "
          "select an appropriate value",
          0, 1000, THEORA_DEF_RATE_BUFFER,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_MULTIPASS_CACHE_FILE,
      g_param_spec_string ("multipass-cache-file", "Multipass Cache File",
          "Multipass cache file", THEORA_DEF_MULTIPASS_CACHE_FILE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  g_object_class_install_property (gobject_class, PROP_MULTIPASS_MODE,
      g_param_spec_enum ("multipass-mode", "Multipass mode",
          "Single pass or first/second pass", GST_TYPE_MULTIPASS_MODE,
          THEORA_DEF_MULTIPASS_MODE,
          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  gstelement_class->change_state = theora_enc_change_state;
}
Exemple #16
0
static GstStateChangeReturn
theora_enc_change_state (GstElement * element, GstStateChange transition)
{
  GstTheoraEnc *enc;
  GstStateChangeReturn ret;

  enc = GST_THEORA_ENC (element);

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      break;
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      GST_DEBUG_OBJECT (enc, "READY->PAUSED Initing theora state");
      th_info_init (&enc->info);
      th_comment_init (&enc->comment);
      enc->packetno = 0;
      enc->force_keyframe = FALSE;

      if (enc->multipass_mode >= MULTIPASS_MODE_FIRST_PASS) {
        GError *err = NULL;

        if (!enc->multipass_cache_file) {
          ret = GST_STATE_CHANGE_FAILURE;
          GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL), (NULL));
          return ret;
        }
        enc->multipass_cache_fd =
            g_io_channel_new_file (enc->multipass_cache_file,
            (enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS ? "w" : "r"),
            &err);

        if (enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS)
          enc->multipass_cache_adapter = gst_adapter_new ();

        if (!enc->multipass_cache_fd) {
          ret = GST_STATE_CHANGE_FAILURE;
          GST_ELEMENT_ERROR (enc, RESOURCE, OPEN_READ, (NULL),
              ("Failed to open multipass cache file: %s", err->message));
          g_error_free (err);
          return ret;
        }

        g_io_channel_set_encoding (enc->multipass_cache_fd, NULL, NULL);
      }
      break;
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
      break;
    default:
      break;
  }

  ret = parent_class->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
      break;
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      GST_DEBUG_OBJECT (enc, "PAUSED->READY Clearing theora state");
      if (enc->encoder) {
        th_encode_free (enc->encoder);
        enc->encoder = NULL;
      }
      th_comment_clear (&enc->comment);
      th_info_clear (&enc->info);

      theora_enc_clear (enc);
      enc->initialised = FALSE;
      break;
    case GST_STATE_CHANGE_READY_TO_NULL:
      break;
    default:
      break;
  }

  return ret;
}
Exemple #17
0
static void th_enc_api_clear(th_api_wrapper *_api){
  if(_api->encode)th_encode_free(_api->encode);
  memset(_api,0,sizeof(*_api));
}