Browse files

FFMPEG::Packet tests

  • Loading branch information...
1 parent eea669e commit 976395b2293c4c2c6b7535e06501a1fd7ae82e2c @drbrain committed Sep 8, 2009
Showing with 61 additions and 6 deletions.
  1. +15 −6 lib/ffmpeg/packet.rb
  2. +46 −0 test/test_ffmpeg_packet.rb
View
21 lib/ffmpeg/packet.rb
@@ -32,15 +32,22 @@ class FFMPEG::Packet
builder.c <<-C
VALUE buffer() {
- AVPacket* packet;
- Data_Get_Struct(self, AVPacket, packet);
+ AVPacket *packet;
+ FrameBuffer *buf = NULL;
+ VALUE buffer;
- VALUE buffer = rb_iv_get(self, "@buffer");
+ Data_Get_Struct(self, AVPacket, packet);
- FrameBuffer * buf = NULL;
+ buffer = rb_iv_get(self, "@buffer");
- if (!NIL_P(buffer)) {
+ switch (TYPE(buffer)) {
+ case T_DATA:
Data_Get_Struct(buffer, FrameBuffer, buf);
+ break;
+ default:
+ if (!NIL_P(buffer)) /* HACK remove FrameBuffer */
+ return buffer;
+ break;
}
if (NIL_P(buffer) || (buf->buf != packet->data)) {
@@ -73,7 +80,7 @@ class FFMPEG::Packet
break;
default:
buffer = rb_str_to_str(buffer);
- packet->data = (uint8_t *)RSTRING_PTR(buffer);
+ packet->data = (uint8_t *)StringValuePtr(buffer);
packet->size = RSTRING_LEN(buffer);
}
@@ -96,6 +103,8 @@ class FFMPEG::Packet
packet->dts = AV_NOPTS_VALUE;
packet->pos = -1;
+ rb_iv_set(self, "@buffer", Qnil);
+
return self;
}
C
View
46 test/test_ffmpeg_packet.rb
@@ -0,0 +1,46 @@
+require 'ffmpeg/test_case'
+
+class TestFFMPEGPacket < FFMPEG::TestCase
+
+ def setup
+ super
+
+ @p = FFMPEG::Packet.new
+ end
+
+ def test_buffer
+ assert_kind_of FFMPEG::FrameBuffer, @p.buffer
+
+ @p.buffer = 'foo'
+
+ assert_equal 'foo', @p.buffer
+ end
+
+ def test_buffer_equals
+ foo = 'foo'
+ @p.buffer = foo
+
+ assert_same foo, @p.buffer
+
+ fb = FFMPEG::FrameBuffer.new 100
+ @p.buffer = FFMPEG::FrameBuffer.new 100
+
+ refute_same fb, @p.buffer
+ end
+
+ def test_clean
+ @p.buffer = 'hi'
+
+ @p.clean
+
+ assert_equal 0, @p.size
+ assert_equal -1, @p.pos
+
+ assert_equal FFMPEG::NOPTS_VALUE, @p.pts
+ assert_equal FFMPEG::NOPTS_VALUE, @p.dts
+
+ assert_kind_of FFMPEG::FrameBuffer, @p.buffer
+ end
+
+end
+

0 comments on commit 976395b

Please sign in to comment.