uint8_t divxEncoderCQ::init (uint32_t q, uint32_t fps1000)
{
  UNUSED_ARG (fps1000);
  _q = q;

  printf (" Compressing %lu x %lu video in qz %lu\n", _w, _h, _q);

// check header and lib match -> good idea !


  if (!params (fps1000))
    return 0;

  setting.vbr_mode = RCMODE_1PASS_CONSTANT_Q;
  setting.quantizer = _q;
  ADM_assert (0 == _init);

  if (ENC_OK != encore ((void *) &_handle, ENC_OPT_INIT, &tag, &setting))
    {
      printf ("\n error initializing divx !\n");
      return 0;

    }
  printf ("\n Divx initialized  OK in CQ mode!\n");
  _init = 1;
  return 1;
}
uint8_t divxEncoderCBR::init (uint32_t q, uint32_t fps1000)
{
  UNUSED_ARG (fps1000);
  _br = q;

  printf (" Compressing %lu x %lu video in CBR %lu\n", _w, _h, _br);

// check header and lib match -> good idea !

  if (!params (fps1000))
    return 0;

  setting.vbr_mode = RCMODE_502_1PASS;	//RCMODE_VBV_1PASS;
  setting.bitrate = _br;
  ADM_assert (0 == _init);

  if (ENC_OK != encore ((void *) &_handle, ENC_OPT_INIT, &tag, &setting))
    {
      printf ("\n error initializing divx !\n");
      return 0;

    }
  _init = 1;
  printf ("\n Divx initialized OK in CBR mode  !\n");
  return 1;
}
uint8_t divxEncoder::params (uint32_t fps1000)
{

  if (ENCORE_VERSION != encore (0, ENC_OPT_VERSION, 0, 0))
    //? interfaces are incompatible, encoding can?t be performed
    {
      printf ("\n Header & lib mismatch for divx !!!\n");
      return 0;
    }

  memset (&tag, 0, sizeof (tag));
  //tag.biSize=sizeof(tag);
  tag.biWidth = _w;
  tag.biHeight = _h;
  tag.biBitCount = 24;
  tag.biCompression = fourCC::get ((uint8_t *) "YV12");

  memset (&setting, 0, sizeof (setting));
  setting.use_bidirect = 0;
  setting.input_frame_period = fps1000;
  setting.input_clock = fps1000;
  setting.complexity_modulation = 0.5;
  setting.quality = 5;

  return 1;
}
Esempio n. 4
0
static void
gst_divxenc_unset (GstDivxEnc * divxenc)
{
  if (divxenc->handle) {
    encore (divxenc->handle, ENC_OPT_RELEASE, NULL, NULL);
    divxenc->handle = NULL;
  }
}
uint8_t divxEncoder::stopEncoder (void)
{
  int
    ret;

  ADM_assert (_init);
  ret = encore (_handle, ENC_OPT_RELEASE, 0, 0);
  _init = 0;
  if (ret == ENC_OK)
    return 1;
  return 0;
}
Esempio n. 6
0
static GstFlowReturn
gst_divxenc_chain (GstPad * pad, GstBuffer * buf)
{
  GstDivxEnc *divxenc;
  GstBuffer *outbuf;
  ENC_FRAME xframe;
  ENC_RESULT xres;
  int res;
  GstFlowReturn ret = GST_FLOW_OK;

  divxenc = GST_DIVXENC (gst_pad_get_parent (pad));

  outbuf = gst_buffer_new_and_alloc (divxenc->buffer_size);
  GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);

  /* encode and so ... */
  xframe.image = GST_BUFFER_DATA (buf);
  xframe.bitstream = (void *) GST_BUFFER_DATA (outbuf);
  xframe.length = GST_BUFFER_SIZE (outbuf);     /* GST_BUFFER_MAXSIZE */
  xframe.produce_empty_frame = 0;

  if ((res = encore (divxenc->handle, ENC_OPT_ENCODE, &xframe, &xres))) {
    goto not_encoding;
  }

  GST_BUFFER_SIZE (outbuf) = xframe.length;

  /* go out, multiply! */
  gst_buffer_set_caps (outbuf, GST_PAD_CAPS (divxenc->srcpad));
  gst_pad_push (divxenc->srcpad, outbuf);

  /* proclaim destiny */
  g_signal_emit (G_OBJECT (divxenc), gst_divxenc_signals[FRAME_ENCODED], 0);

  /* until the final judgement */
  goto done;

not_encoding:

  GST_ELEMENT_ERROR (divxenc, LIBRARY, ENCODE, (NULL),
      ("Error encoding divx frame: %s (%d)", gst_divxenc_error (res), res));
  ret = GST_FLOW_ERROR;
  gst_buffer_unref (outbuf);
  goto done;

done:
  gst_buffer_unref (buf);
  gst_object_unref (divxenc);
  return ret;

}
Esempio n. 7
0
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void find_defense_solve(slice_index si)
{
  stip_length_type result_intermediate = immobility_on_next_move;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  while (result_intermediate<=MOVE_HAS_SOLVED_LENGTH() && encore())
  {
    pipe_solve_delegate(si);
    assert(slack_length<=solve_result || solve_result==this_move_is_illegal);
    if (result_intermediate<solve_result)
      result_intermediate = solve_result;
  }

  solve_result = result_intermediate;

  if (encore())
    post_move_iteration_cancel();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Esempio n. 8
0
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void find_attack_solve(slice_index si)
{
  stip_length_type result_intermediate = MOVE_HAS_NOT_SOLVED_LENGTH();

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  while (encore() && result_intermediate>MOVE_HAS_SOLVED_LENGTH())
  {
    pipe_solve_delegate(si);
    assert(slack_length<=solve_result || solve_result==this_move_is_illegal);
    if (slack_length<solve_result && solve_result<result_intermediate)
      result_intermediate = solve_result;
  }

  solve_result = result_intermediate;

  if (encore())
    post_move_iteration_cancel();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Esempio n. 9
0
static boolean find_flights(slice_index si,
                            Side side_in_check,
                            unsigned int nr_flights_to_find)
{
  unsigned int nr_flights_found = 0;
  square const save_king_square = being_solved.king_square[side_in_check];
  piece_walk_type const king_walk = get_walk_of_piece_on_square(save_king_square);
  Flags const king_flags = being_solved.spec[save_king_square];
  square const save_departure = curr_generation->departure ;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  siblingply(side_in_check);

  curr_generation->departure = save_king_square;
  move_generation_current_walk = king_walk;
  generate_moves_for_piece_based_on_walk();

  empty_square(save_king_square);

  while (encore())
  {
    being_solved.king_square[side_in_check] = move_generation_stack[CURRMOVE_OF_PLY(nbply)].arrival;
    if ((is_square_empty(being_solved.king_square[side_in_check])
         || TSTFLAG(being_solved.spec[being_solved.king_square[side_in_check]],advers(side_in_check)))
        && being_solved.king_square[side_in_check]!=being_solved.king_square[advers(side_in_check)]
        && !pipe_is_in_check_recursive_delegate(si,side_in_check))
      ++nr_flights_found;

    pop_move();
  }

  being_solved.king_square[side_in_check] = save_king_square;
  occupy_square(save_king_square,king_walk,king_flags);

  curr_generation->departure = save_departure;

  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",nr_flights_found>nr_flights_to_find);
  TraceFunctionResultEnd();
  return nr_flights_found>nr_flights_to_find;
}
Esempio n. 10
0
static gboolean
plugin_init (GstPlugin * plugin)
{
  int lib_version;

  lib_version = encore (NULL, ENC_OPT_VERSION, 0, 0);
  if (lib_version != ENCORE_VERSION) {
    g_warning ("Version mismatch! This plugin was compiled for "
        "DivX version %d, while your library has version %d!",
        ENCORE_VERSION, lib_version);
    return FALSE;
  }

  /* create an elementfactory for the v4lmjpegsrcparse element */
  return gst_element_register (plugin, "divxenc",
      GST_RANK_NONE, GST_TYPE_DIVXENC);
}
uint8_t
  divxEncoder::encode (uint8_t * in,
		       uint8_t * out, uint32_t * len, uint32_t * flags)
{

  int ret;
  ENC_FRAME frame;

  ADM_assert (_init);
  memset (&frame, 0, sizeof (frame));
  frame.image = in;
  frame.bitstream = out;

  ret = encore (_handle, ENC_OPT_ENCODE, &frame, &result);
  if (ENC_OK != ret)
    {
      printf ("Error encoding frame divx :%d \n", ret);
      return 0;
    }
  *len = (uint32_t) frame.length;
  *flags = 0;
  switch (result.cType)
    {
    case '0':
      *flags = 0;
      *len = 0;
      break;
    case 'I':
      *flags = AVI_KEY_FRAME;
      break;
    case 'P':
      break;
    case 'B':
      *flags = AVI_B_FRAME;
      break;

    }
  return 1;
}
Esempio n. 12
0
static gboolean
gst_divxenc_setup (GstDivxEnc * divxenc)
{
  void *handle = NULL;
  SETTINGS output;
  DivXBitmapInfoHeader input;
  int ret;

  /* set it up */
  memset (&input, 0, sizeof (DivXBitmapInfoHeader));
  input.biSize = sizeof (DivXBitmapInfoHeader);
  input.biWidth = divxenc->width;
  input.biHeight = divxenc->height;
  input.biBitCount = divxenc->bitcnt;
  input.biCompression = divxenc->csp;

  memset (&output, 0, sizeof (SETTINGS));
  output.vbr_mode = RCMODE_VBV_1PASS;
  output.bitrate = divxenc->bitrate;
  output.quantizer = 0;
  output.use_bidirect = 1;
  output.input_clock = 0;
  output.input_frame_period = 1000000;
  output.internal_timescale = (divxenc->fps_n / divxenc->fps_d) * 1000000;      /* FIX? */
  output.max_key_interval = (divxenc->max_key_interval == -1) ?
      150 : divxenc->max_key_interval;
  output.key_frame_threshold = 50;
  output.vbv_bitrate = 0;
  output.vbv_size = 0;
  output.vbv_occupancy = 0;
  output.complexity_modulation = 0;
  output.deinterlace = 0;
  output.quality = divxenc->quality;
  output.data_partitioning = 0;
  output.quarter_pel = 1;
  output.use_gmc = 1;
  output.psychovisual = 0;
  output.pv_strength_frame = 0;
  output.pv_strength_MB = 0;
  output.interlace_mode = 0;
  output.enable_crop = 0;
  output.enable_resize = 0;
  output.temporal_enable = 1;
  output.spatial_passes = 3;
  output.spatial_level = 1.0;
  output.temporal_level = 1.0;

  if ((ret = encore (&handle, ENC_OPT_INIT, &input, &output))) {
    GST_ELEMENT_ERROR (divxenc, LIBRARY, SETTINGS, (NULL),
        ("Error setting up divx encoder: %s (%d)",
            gst_divxenc_error (ret), ret));
    return FALSE;
  }

  divxenc->handle = handle;

  /* set buffer size to theoretical limit (see docs on divx.com) */
  divxenc->buffer_size = 6 * divxenc->width * divxenc->height;

  return TRUE;
}