/gmf/Datasource.go

https://code.google.com/p/gmf/ · Go · 39 lines · 32 code · 7 blank · 0 comment · 4 complexity · c1aa8038aedf92cf160bb281f74e114c MD5 · raw file

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