VLCStreamOutput.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // VLCStreamOutput.m
  3. // VLCKit
  4. //
  5. // Created by Pierre d'Herbemont on 1/12/08.
  6. // Copyright 2008 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "VLCStreamOutput.h"
  9. #import "VLCLibVLCBridging.h"
  10. @implementation VLCStreamOutput
  11. - (id)initWithOptionDictionary:(NSDictionary *)dictionary
  12. {
  13. if( self = [super init] )
  14. {
  15. options = [[NSMutableDictionary dictionaryWithDictionary:dictionary] retain];
  16. }
  17. return self;
  18. }
  19. - (NSString *)description
  20. {
  21. return [self representedLibVLCOptions];
  22. }
  23. + (id)streamOutputWithOptionDictionary:(NSDictionary *)dictionary
  24. {
  25. return [[[self alloc] initWithOptionDictionary:dictionary] autorelease];
  26. }
  27. + (id)rtpBroadcastStreamOutputWithSAPAnnounce:(NSString *)announceName
  28. {
  29. return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
  30. [NSDictionary dictionaryWithObjectsAndKeys:
  31. @"ts", @"muxer",
  32. @"file", @"access",
  33. @"sap", @"sdp",
  34. [announceName copy], @"name",
  35. @"239.255.1.1", @"destination", nil
  36. ], @"rtpOptions",
  37. nil
  38. ]
  39. ];
  40. }
  41. + (id)rtpBroadcastStreamOutput
  42. {
  43. return [self rtpBroadcastStreamOutputWithSAPAnnounce:@"Helloworld!"];
  44. }
  45. + (id)ipodStreamOutputWithFilePath:(NSString *)filePath
  46. {
  47. return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
  48. [NSDictionary dictionaryWithObjectsAndKeys:
  49. @"mp4v", @"videoCodec",
  50. @"1024", @"videoBitrate",
  51. @"mp4a", @"audioCodec",
  52. @"192", @"audioBitrate",
  53. @"2", @"channels",
  54. @"320", @"width",
  55. @"240", @"canvasHeight",
  56. @"Yes", @"audio-sync",
  57. nil
  58. ], @"transcodingOptions",
  59. [NSDictionary dictionaryWithObjectsAndKeys:
  60. @"mp4", @"muxer",
  61. @"file", @"access",
  62. [filePath copy], @"destination", nil
  63. ], @"outputOptions",
  64. nil
  65. ]
  66. ];
  67. }
  68. + (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath
  69. {
  70. return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
  71. [NSDictionary dictionaryWithObjectsAndKeys:
  72. @"mp4v", @"videoCodec",
  73. @"1024", @"videoBitrate",
  74. @"mp4a", @"audioCodec",
  75. @"192", @"audioBitrate",
  76. nil
  77. ], @"transcodingOptions",
  78. [NSDictionary dictionaryWithObjectsAndKeys:
  79. @"mp4", @"muxer",
  80. @"file", @"access",
  81. [filePath copy], @"destination", nil
  82. ], @"outputOptions",
  83. nil
  84. ]
  85. ];
  86. }
  87. + (id)streamOutputWithFilePath:(NSString *)filePath
  88. {
  89. return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
  90. [NSDictionary dictionaryWithObjectsAndKeys:
  91. @"ps", @"muxer",
  92. @"file", @"access",
  93. [filePath copy], @"destination", nil
  94. ], @"outputOptions",
  95. nil
  96. ]
  97. ];
  98. }
  99. + (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath;
  100. {
  101. return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
  102. [NSDictionary dictionaryWithObjectsAndKeys:
  103. @"mp2v", @"videoCodec",
  104. @"1024", @"videoBitrate",
  105. @"mp2a", @"audioCodec",
  106. @"128", @"audioBitrate",
  107. @"Yes", @"audio-sync",
  108. nil
  109. ], @"transcodingOptions",
  110. [NSDictionary dictionaryWithObjectsAndKeys:
  111. @"mpeg", @"muxer",
  112. @"file", @"access",
  113. [filePath copy], @"destination", nil
  114. ], @"outputOptions",
  115. nil
  116. ]
  117. ];
  118. }
  119. @end
  120. @implementation VLCStreamOutput (LibVLCBridge)
  121. - (NSString *)representedLibVLCOptions
  122. {
  123. NSString * representedOptions;
  124. NSMutableArray * subOptions = [NSMutableArray array];
  125. NSMutableArray * optionsAsArray = [NSMutableArray array];
  126. NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
  127. if( transcodingOptions )
  128. {
  129. NSString * videoCodec = [transcodingOptions objectForKey:@"videoCodec"];
  130. NSString * audioCodec = [transcodingOptions objectForKey:@"audioCodec"];
  131. NSString * videoBitrate = [transcodingOptions objectForKey:@"videoBitrate"];
  132. NSString * audioBitrate = [transcodingOptions objectForKey:@"audioBitrate"];
  133. NSString * channels = [transcodingOptions objectForKey:@"channels"];
  134. NSString * height = [transcodingOptions objectForKey:@"height"];
  135. NSString * canvasHeight = [transcodingOptions objectForKey:@"canvasHeight"];
  136. NSString * width = [transcodingOptions objectForKey:@"width"];
  137. NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"];
  138. NSString * videoEncoder = [transcodingOptions objectForKey:@"videoEncoder"];
  139. if( videoEncoder ) [subOptions addObject:[NSString stringWithFormat:@"venc=%@", videoEncoder]];
  140. if( videoCodec ) [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]];
  141. if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]];
  142. if( width ) [subOptions addObject:[NSString stringWithFormat:@"width=%@", width]];
  143. if( height ) [subOptions addObject:[NSString stringWithFormat:@"height=%@", height]];
  144. if( canvasHeight ) [subOptions addObject:[NSString stringWithFormat:@"canvas-height=%@", canvasHeight]];
  145. if( audioCodec ) [subOptions addObject:[NSString stringWithFormat:@"acodec=%@", audioCodec]];
  146. if( audioBitrate ) [subOptions addObject:[NSString stringWithFormat:@"ab=%@", audioBitrate]];
  147. if( channels ) [subOptions addObject:[NSString stringWithFormat:@"channels=%@", channels]];
  148. if( audioSync ) [subOptions addObject:[NSString stringWithFormat:@"audioSync", width]];
  149. [optionsAsArray addObject: [NSString stringWithFormat:@"transcode{%@}", [subOptions componentsJoinedByString:@","]]];
  150. [subOptions removeAllObjects];
  151. }
  152. NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
  153. if( outputOptions )
  154. {
  155. NSString * muxer = [outputOptions objectForKey:@"muxer"];
  156. NSString * destination = [outputOptions objectForKey:@"destination"];
  157. NSString * url = [outputOptions objectForKey:@"url"];
  158. NSString * access = [outputOptions objectForKey:@"access"];
  159. if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"mux=%@", muxer]];
  160. if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
  161. if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
  162. if( access ) [subOptions addObject:[NSString stringWithFormat:@"access=%@", access]];
  163. [optionsAsArray addObject:[NSString stringWithFormat:@"std{%@}", [subOptions componentsJoinedByString:@","]]];
  164. [subOptions removeAllObjects];
  165. }
  166. NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
  167. if( rtpOptions )
  168. {
  169. NSString * muxer = [rtpOptions objectForKey:@"muxer"];
  170. NSString * destination = [rtpOptions objectForKey:@"destination"];
  171. NSString * sdp = [rtpOptions objectForKey:@"sdp"];
  172. NSString * name = [rtpOptions objectForKey:@"name"];
  173. if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
  174. if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=%@", destination]];
  175. if( sdp ) [subOptions addObject:[NSString stringWithFormat:@"sdp=%@", sdp]];
  176. if( name ) [subOptions addObject:[NSString stringWithFormat:@"name=\"%@\"", name]];
  177. [optionsAsArray addObject:[NSString stringWithFormat:@"rtp{%@}", [subOptions componentsJoinedByString:@","]]];
  178. [subOptions removeAllObjects];
  179. }
  180. representedOptions = [optionsAsArray componentsJoinedByString:@":"];
  181. return representedOptions;
  182. }
  183. @end