/* * myLib - https://github.com/taktod/myLib * Copyright (c) 2014 ttProject. All rights reserved. * * Licensed under GNU GENERAL PUBLIC LICENSE Version 3. */ package com.ttProject.xuggle.frame.test; import org.apache.log4j.Logger; import org.junit.Test; import com.ttProject.container.IContainer; import com.ttProject.container.IReader; import com.ttProject.container.mkv.MkvTagReader; import com.ttProject.container.mkv.type.SimpleBlock; import com.ttProject.frame.IAudioFrame; import com.ttProject.frame.IFrame; import com.ttProject.frame.IVideoFrame; import com.ttProject.nio.channels.FileReadChannel; import com.ttProject.nio.channels.IFileReadChannel; /** * mkvコンテナのデコード動作テスト * @author taktod */ public class MkvContainerTest { /** ロガー */ private Logger logger = Logger.getLogger(MkvContainerTest.class); @Test public void h264() throws Exception { decodeTest( FileReadChannel.openFileReadChannel( Thread.currentThread().getContextClassLoader().getResource("h264.mkv") ) ); } @Test public void aac() throws Exception { decodeTest( FileReadChannel.openFileReadChannel( Thread.currentThread().getContextClassLoader().getResource("aac.mkv") ) ); } private void decodeTest(IFileReadChannel source) { DecodeBase base = new DecodeBase(); try { IReader reader = new MkvTagReader(); IContainer container = null; while((container = reader.read(source)) != null) { if(container instanceof SimpleBlock) { SimpleBlock simpleBlock = (SimpleBlock)container; IFrame frame = simpleBlock.getFrame(); logger.info(frame); if(frame instanceof IAudioFrame) { base.processAudioDecode((IAudioFrame)frame); } else if(frame instanceof IVideoFrame) { base.processVideoDecode((IVideoFrame)frame); } } } } catch(Exception e) { logger.error("例外発生", e); } finally { if(base != null) { base.close(); base = null; } if(source != null) { try { source.close(); } catch(Exception e) { } source = null; } } } }