DataSourceWrapper.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**********************************************************************************
  2. AudioPlayer.m
  3. Created by Thong Nguyen on 16/10/2012.
  4. https://github.com/tumtumtum/audjustable
  5. Copyright (c) 2012 Thong Nguyen (tumtumtum@gmail.com). All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. 3. All advertising materials mentioning features or use of this software
  14. must display the following acknowledgement:
  15. This product includes software developed by Thong Nguyen (tumtumtum@gmail.com)
  16. 4. Neither the name of Thong Nguyen nor the
  17. names of its contributors may be used to endorse or promote products
  18. derived from this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY Thong Nguyen''AS IS'' AND ANY
  20. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  23. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. **********************************************************************************/
  30. #import "DataSourceWrapper.h"
  31. @interface DataSourceWrapper()
  32. @property (readwrite) DataSource* innerDataSource;
  33. @end
  34. @implementation DataSourceWrapper
  35. -(id) initWithDataSource:(DataSource*)innerDataSourceIn
  36. {
  37. if (self = [super init])
  38. {
  39. self.innerDataSource = innerDataSourceIn;
  40. self.innerDataSource.delegate = self;
  41. }
  42. return self;
  43. }
  44. -(AudioFileTypeID) audioFileTypeHint
  45. {
  46. return self.innerDataSource.audioFileTypeHint;
  47. }
  48. -(void) dealloc
  49. {
  50. self.innerDataSource.delegate = nil;
  51. }
  52. -(long long) length
  53. {
  54. return self.innerDataSource.length;
  55. }
  56. -(void) seekToOffset:(long long)offset
  57. {
  58. return [self.innerDataSource seekToOffset:offset];
  59. }
  60. -(int) readIntoBuffer:(UInt8*)buffer withSize:(int)size
  61. {
  62. return [self.innerDataSource readIntoBuffer:buffer withSize:size];
  63. }
  64. -(long long) position
  65. {
  66. return self.innerDataSource.position;
  67. }
  68. -(BOOL) registerForEvents:(NSRunLoop*)runLoop
  69. {
  70. return [self.innerDataSource registerForEvents:runLoop];
  71. }
  72. -(void) unregisterForEvents
  73. {
  74. [self.innerDataSource unregisterForEvents];
  75. }
  76. -(void) close
  77. {
  78. [self.innerDataSource close];
  79. }
  80. -(BOOL) hasBytesAvailable
  81. {
  82. return self.innerDataSource.hasBytesAvailable;
  83. }
  84. -(void) dataSourceDataAvailable:(DataSource*)dataSource
  85. {
  86. [self.delegate dataSourceDataAvailable:self];
  87. }
  88. -(void) dataSourceErrorOccured:(DataSource*)dataSource
  89. {
  90. [self.delegate dataSourceErrorOccured:self];
  91. }
  92. -(void) dataSourceEof:(DataSource*)dataSource
  93. {
  94. [self.delegate dataSourceEof:self];
  95. }
  96. @end