All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.libav.avformat.StreamWrapper53 Maven / Gradle / Ivy

/*
 * Copyright (C) 2012 Ondrej Perutka
 *
 * This program is free software: you can redistribute it and/or 
 * modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation, either 
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library. If not, see 
 * .
 */
package org.libav.avformat;

import com.sun.jna.Pointer;
import org.libav.avcodec.CodecContextWrapperFactory;
import org.libav.avcodec.ICodecContextWrapper;
import org.libav.avformat.bridge.AVStream53;
import org.libav.avutil.bridge.AVRational;
import org.libav.avutil.bridge.IAVUtilLibrary;
import org.libav.bridge.LibraryManager;
import org.libav.util.Rational;

/**
 * Wrapper class for the AVStream54.
 * 
 * @author Ondrej Perutka
 */
public class StreamWrapper53 extends AbstractStreamWrapper {
    
    private AVStream53 stream;
    
    /**
     * Create a new wrapper for the given AVStream.
     * 
     * @param stream an AVStream structure
     */
    public StreamWrapper53(AVStream53 stream) {
        this.stream = stream;
    }
    
    @Override
    public Pointer getPointer() {
        if (stream == null)
            return null;
        
        return stream.getPointer();
    }
    
    @Override
    public void free() {
        if (stream == null)
            return;
        
        IAVUtilLibrary lib = LibraryManager.getInstance().getAVUtilLibraryWrapper().getLibrary();
        lib.av_free(stream.getPointer());
        stream = null;
    }
    
    @Override
    public ICodecContextWrapper getCodecContext() {
        if (stream == null)
            return null;
        
        if (codecContext == null) {
            Pointer p = (Pointer)stream.readField("codec");
            codecContext = p == null ? null : CodecContextWrapperFactory.getInstance().wrap(p);
        }
        
        return codecContext;
    }
    
    @Override
    public void setCodecContext(ICodecContextWrapper codecContext) {
        if (stream == null)
            return;
        
        stream.writeField("codec", codecContext == null ? null : codecContext.getPointer());
        this.codecContext = codecContext;
    }
    
    @Override
    public int getIndex() {
        if (stream == null)
            return -1;
        
        if (index == null)
            index = (Integer)stream.readField("index");
        
        return index;
    }

    @Override
    public Rational getRFrameRate() {
        if (stream == null)
            return null;
        
        if (frameRate == null)
            frameRate = new Rational((AVRational)stream.readField("r_frame_rate"));
        
        return frameRate;
    }

    @Override
    public Rational getTimeBase() {
        if (stream == null)
            return null;
        
        if (timeBase == null)
            timeBase = new Rational((AVRational)stream.readField("time_base"));
        
        return timeBase;
    }
    
    @Override
    public void setTimeBase(Rational timeBase) {
        if (stream == null)
            return;
        
        if (timeBase == null)
            timeBase = new Rational(0, 0);
        
        AVRational avr = new AVRational((int)timeBase.getNumerator(), (int)timeBase.getDenominator());
        stream.writeField("time_base", avr);
        this.timeBase = timeBase;
    }

    @Override
    public long getFrameCount() {
        if (stream == null)
            return -1;
        
        if (frameCount == null)
            frameCount = (Long)stream.readField("nb_frames");
        
        return frameCount;
    }
    
    @Override
    public long getDuration() {
        if (stream == null)
            return -1;
        
        if (duration == null)
            duration = (Long)stream.readField("duration");
        
        return duration;
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy