|
| 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) |
0 commit comments