~ubuntu-branches/ubuntu/lucid/schroedinger/lucid

« back to all changes in this revision

Viewing changes to gst/gstschroenc.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-03-16 18:26:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080316182629-6ofrq5h72ddrl1oo
Tags: 1.0.1-2
* debian/patches/01_no-x86-opcodes.patch:
  + Don't use x86 opcodes, these obviously don't work on non-x86 archs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
  uint64_t granulepos_low;
74
74
  uint64_t granulepos_hi;
75
75
  gboolean started;
 
76
  gint64 timestamp_offset;
 
77
  int picture_number;
76
78
 
77
79
  SchroEncoder *encoder;
78
80
  SchroVideoFormat *video_format;
264
266
  schro_enc->video_format->aspect_ratio_numerator = schro_enc->par_n;
265
267
  schro_enc->video_format->aspect_ratio_denominator = schro_enc->par_d;
266
268
 
 
269
  schro_video_format_set_std_signal_range (schro_enc->video_format,
 
270
      SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
 
271
  schro_video_format_set_std_colour_spec (schro_enc->video_format,
 
272
      SCHRO_COLOUR_SPEC_HDTV);
 
273
 
267
274
  schro_encoder_set_video_format (schro_enc->encoder, schro_enc->video_format);
268
275
 
269
276
  schro_enc->duration = gst_util_uint64_scale_int (GST_SECOND,
429
436
}
430
437
 
431
438
#define OGG_DIRAC_GRANULE_SHIFT 30
432
 
#define OGG_DIRAC_GRANULE_LOW_MASK ((1<<OGG_DIRAC_GRANULE_SHIFT)-1)
 
439
#define OGG_DIRAC_GRANULE_LOW_MASK ((1ULL<<OGG_DIRAC_GRANULE_SHIFT)-1)
433
440
 
434
441
static gint64
435
442
granulepos_to_frame (gint64 granulepos)
632
639
    GST_DEBUG("using granulepos offset %lld", schro_enc->granulepos_offset);
633
640
    schro_enc->granulepos_hi = 0;
634
641
    schro_enc->got_offset = TRUE;
 
642
 
 
643
    schro_enc->timestamp_offset = GST_BUFFER_TIMESTAMP(buf);
 
644
    schro_enc->picture_number = 0;
635
645
  }
636
646
  if (!schro_enc->started) {
637
647
    schro_encoder_start (schro_enc->encoder);
672
682
          /* FIXME This shouldn't happen */
673
683
          return GST_FLOW_ERROR;
674
684
        }
675
 
        parse_code = encoded_buffer->data[5];
 
685
        parse_code = encoded_buffer->data[4];
676
686
 
677
687
        if (SCHRO_PARSE_CODE_IS_SEQ_HEADER(parse_code)) {
678
688
          schro_enc->granulepos_hi = schro_enc->granulepos_offset +
685
695
        outbuf = gst_buffer_new_and_alloc (encoded_buffer->length);
686
696
        memcpy (GST_BUFFER_DATA (outbuf), encoded_buffer->data,
687
697
            encoded_buffer->length);
688
 
        gst_buffer_set_caps (outbuf, gst_pad_get_caps(schro_enc->srcpad));
689
 
 
690
 
        GST_BUFFER_OFFSET_END (outbuf) =
691
 
          (schro_enc->granulepos_hi<<30) + schro_enc->granulepos_low;
692
 
        GST_BUFFER_OFFSET (outbuf) = gst_util_uint64_scale (
693
 
            (schro_enc->granulepos_hi + schro_enc->granulepos_low),
694
 
            schro_enc->fps_d * GST_SECOND, schro_enc->fps_n);
695
 
 
696
 
        GST_BUFFER_TIMESTAMP (outbuf) = gst_util_uint64_scale (
697
 
            (schro_enc->granulepos_hi + schro_enc->granulepos_low),
698
 
            schro_enc->fps_d * GST_SECOND, schro_enc->fps_n);
 
698
        gst_buffer_set_caps (outbuf,
 
699
            gst_caps_new_simple ("video/x-dirac",
 
700
              "width", G_TYPE_INT, schro_enc->width,
 
701
              "height", G_TYPE_INT, schro_enc->height,
 
702
              "framerate", GST_TYPE_FRACTION, schro_enc->fps_n,
 
703
              schro_enc->fps_d,
 
704
              NULL));
699
705
 
700
706
        if (SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
 
707
          GST_BUFFER_OFFSET_END (outbuf) =
 
708
            (schro_enc->granulepos_hi<<OGG_DIRAC_GRANULE_SHIFT) +
 
709
            schro_enc->granulepos_low;
 
710
          GST_BUFFER_OFFSET (outbuf) = gst_util_uint64_scale (
 
711
              (schro_enc->granulepos_hi + schro_enc->granulepos_low),
 
712
              schro_enc->fps_d * GST_SECOND, schro_enc->fps_n);
701
713
          GST_BUFFER_DURATION (outbuf) = schro_enc->duration;
 
714
          GST_BUFFER_TIMESTAMP (outbuf) = 
 
715
            schro_enc->timestamp_offset + gst_util_uint64_scale (
 
716
              schro_enc->picture_number,
 
717
              schro_enc->fps_d * GST_SECOND, schro_enc->fps_n);
 
718
          schro_enc->picture_number++;
 
719
          if (!SCHRO_PARSE_CODE_IS_INTRA(parse_code)) {
 
720
            GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
 
721
          }
702
722
        } else {
703
 
          GST_BUFFER_DURATION (outbuf) = 0;
 
723
          GST_BUFFER_OFFSET_END (outbuf) = 0;
 
724
          GST_BUFFER_OFFSET (outbuf) = 0;
 
725
          GST_BUFFER_DURATION (outbuf) = -1;
 
726
          //GST_BUFFER_TIMESTAMP (outbuf) = -1;
 
727
          GST_BUFFER_TIMESTAMP (outbuf) = 
 
728
            schro_enc->timestamp_offset + gst_util_uint64_scale (
 
729
              schro_enc->picture_number,
 
730
              schro_enc->fps_d * GST_SECOND, schro_enc->fps_n);
704
731
        }
705
732
 
706
733
        GST_INFO("size %d offset %lld granulepos %llu:%llu timestamp %lld duration %lld",
707
734
            GST_BUFFER_SIZE (outbuf),
708
735
            GST_BUFFER_OFFSET (outbuf),
709
 
            GST_BUFFER_OFFSET_END (outbuf)>>30,
710
 
            GST_BUFFER_OFFSET_END (outbuf)&((1<<30) - 1),
 
736
            GST_BUFFER_OFFSET_END (outbuf)>>OGG_DIRAC_GRANULE_SHIFT,
 
737
            GST_BUFFER_OFFSET_END (outbuf)&OGG_DIRAC_GRANULE_LOW_MASK,
711
738
            GST_BUFFER_TIMESTAMP (outbuf),
712
739
            GST_BUFFER_DURATION (outbuf));
713
740
 
714
 
        if (SCHRO_PARSE_CODE_IS_INTRA(parse_code)) {
715
 
          GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
716
 
        }
717
 
 
718
741
        schro_buffer_unref (encoded_buffer);
719
742
        
720
743
        ret = gst_pad_push (schro_enc->srcpad, outbuf);