Skip to content

Commit 9c90c2d

Browse files
author
Clement Champetier
committed
pyTest: add tests to check Video/Audio frames
1 parent eb3f708 commit 9c90c2d

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

test/pyTest/testAudioFrame.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from nose.tools import *
2+
3+
from pyAvTranscoder import avtranscoder as av
4+
5+
6+
@raises(MemoryError)
7+
def testInvalidAudioFrameAutoAllocated():
8+
"""
9+
Try to create an invalid AudioFrame automatically allocated.
10+
"""
11+
desc = av.AudioFrameDesc(4800, 1, "toto")
12+
av.AudioFrame(desc)
13+
14+
15+
@raises(MemoryError)
16+
def testInvalidAudioFrameManualAllocated():
17+
"""
18+
Try to create an invalid AudioFrame manually allocated.
19+
"""
20+
sampleRate = 48000
21+
nbChannels = 1
22+
sampleFormat = "titi"
23+
desc = av.AudioFrameDesc(sampleRate, nbChannels, sampleFormat)
24+
frame = av.AudioFrame(desc, False)
25+
26+
assert_equals(frame.isDataAllocated(), False)
27+
assert_equals(frame.getSize(), 0)
28+
assert_equals(frame.getSampleRate(), sampleRate)
29+
assert_equals(frame.getNbChannels(), nbChannels)
30+
assert_equals(frame.getChannelLayoutDesc(), "mono")
31+
assert_equals(frame.getNbSamplesPerChannel(), 1920)
32+
assert_equals(frame.getBytesPerSample(), 0)
33+
assert_equals(av.getSampleFormatName(frame.getSampleFormat()), "")
34+
35+
frame.allocateData()
36+
37+
def testAudioFrame():
38+
"""
39+
Check the size and the data buffer of a AudioFrame.
40+
"""
41+
sampleRate = 48000
42+
nbChannels = 1
43+
sampleFormat = "s32"
44+
desc = av.AudioFrameDesc(sampleRate, nbChannels, sampleFormat)
45+
frame = av.AudioFrame(desc)
46+
47+
assert_equals(frame.isDataAllocated(), True)
48+
assert_equals(frame.isAudioFrame(), True)
49+
assert_equals(frame.getSize(), frame.getNbSamplesPerChannel() * frame.getBytesPerSample() * nbChannels)
50+
51+
frame.freeData()
52+
assert_equals(frame.isDataAllocated(), False)

test/pyTest/testVideoFrame.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from nose.tools import *
2+
3+
from pyAvTranscoder import avtranscoder as av
4+
5+
6+
@raises(MemoryError)
7+
def testInvalidVideoFrameAutoAllocated():
8+
"""
9+
Try to create an invalid VideoFrame automatically allocated.
10+
"""
11+
desc = av.VideoFrameDesc(1920, 1080, "toto")
12+
av.VideoFrame(desc)
13+
14+
15+
@raises(MemoryError)
16+
def testInvalidVideoFrameManualAllocated():
17+
"""
18+
Try to create an invalid VideoFrame manually allocated.
19+
"""
20+
width = 1920
21+
height = 1080
22+
pixelFormat = "titi"
23+
desc = av.VideoFrameDesc(width, height, pixelFormat)
24+
frame = av.VideoFrame(desc, False)
25+
26+
assert_equals(frame.isDataAllocated(), False)
27+
assert_equals(frame.getSize(), 0)
28+
assert_equals(frame.getWidth(), width)
29+
assert_equals(frame.getHeight(), height)
30+
assert_equals(av.getPixelFormatName(frame.getPixelFormat()), "")
31+
32+
frame.allocateData()
33+
34+
def testVideoFrame():
35+
"""
36+
Check the size and the data buffer of a VideoFrame.
37+
"""
38+
width = 1920
39+
height = 1080
40+
pixelFormat = "yuv420p"
41+
desc = av.VideoFrameDesc(width, height, pixelFormat)
42+
frame = av.VideoFrame(desc)
43+
44+
assert_equals(frame.isDataAllocated(), True)
45+
assert_equals(frame.isVideoFrame(), True)
46+
assert_equals(frame.getSize(), width * height * 1.5)
47+
48+
frame.freeData()
49+
assert_equals(frame.isDataAllocated(), False)

0 commit comments

Comments
 (0)