PageRenderTime 92ms CodeModel.GetById 85ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/gmf/Datasource.go

https://code.google.com/p/gmf/
Go | 39 lines | 32 code | 7 blank | 0 comment | 4 complexity | c1aa8038aedf92cf160bb281f74e114c MD5 | raw file
 1package gmf
 2
 3import (
 4    "os"
 5    )
 6
 7type DataSource struct {
 8	Locator MediaLocator
 9	ctx     *FormatContext
10	valid   bool
11}
12
13
14func (src *DataSource) Connect() os.Error {
15	src.valid = false
16	src.ctx = avformat_alloc_context()
17	result := av_open_input_file(src.ctx, src.Locator.Filename, nil, 0, nil)
18	if result != 0 {
19		return os.NewError("file not opened 123"+string(result))
20	}
21	result = av_find_stream_info(src.ctx)
22	if result < 0 {
23		return os.NewError("could not find stream info")
24	}
25	src.valid = true
26	return nil
27}
28
29func (src *DataSource) Disconnect() os.Error {
30	if src.valid {
31		av_close_input_file(src.ctx)
32	}
33	return nil
34}
35
36
37func NewDataSource(loc MediaLocator) *DataSource {
38	return &DataSource{Locator: loc, ctx: nil, valid: false}
39}