VLCStreamOutput.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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];
  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. @"x264", @"videoCodec",
  50. @"768", @"videoBitrate",
  51. @"mp4a", @"audioCodec",
  52. @"128", @"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. @end
  69. @implementation VLCStreamOutput (LibVLCBridge)
  70. - (NSString *)representedLibVLCOptions
  71. {
  72. NSString * representedOptions;
  73. NSMutableArray * subOptions = [NSMutableArray array];
  74. NSMutableArray * optionsAsArray = [NSMutableArray array];
  75. NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
  76. if( transcodingOptions )
  77. {
  78. NSString * videoCodec = [transcodingOptions objectForKey:@"videoCodec"];
  79. NSString * audioCodec = [transcodingOptions objectForKey:@"audioCodec"];
  80. NSString * videoBitrate = [transcodingOptions objectForKey:@"videoBitrate"];
  81. NSString * audioBitrate = [transcodingOptions objectForKey:@"audioBitrate"];
  82. NSString * channels = [transcodingOptions objectForKey:@"channels"];
  83. NSString * height = [transcodingOptions objectForKey:@"height"];
  84. NSString * canvasHeight = [transcodingOptions objectForKey:@"canvasHeight"];
  85. NSString * width = [transcodingOptions objectForKey:@"width"];
  86. NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"];
  87. if( videoCodec ) [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]];
  88. if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]];
  89. if( width ) [subOptions addObject:[NSString stringWithFormat:@"width=%@", width]];
  90. if( height ) [subOptions addObject:[NSString stringWithFormat:@"height=%@", height]];
  91. if( canvasHeight ) [subOptions addObject:[NSString stringWithFormat:@"canvas-height=%@", canvasHeight]];
  92. if( audioCodec ) [subOptions addObject:[NSString stringWithFormat:@"acodec=%@", audioCodec]];
  93. if( audioBitrate ) [subOptions addObject:[NSString stringWithFormat:@"ab=%@", audioBitrate]];
  94. if( channels ) [subOptions addObject:[NSString stringWithFormat:@"channels=%@", channels]];
  95. if( audioSync ) [subOptions addObject:[NSString stringWithFormat:@"audioSync", width]];
  96. [optionsAsArray addObject: [NSString stringWithFormat:@"transcode{%@}", [subOptions componentsJoinedByString:@","]]];
  97. [subOptions removeAllObjects];
  98. }
  99. NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
  100. if( outputOptions )
  101. {
  102. NSString * muxer = [outputOptions objectForKey:@"muxer"];
  103. NSString * destination = [outputOptions objectForKey:@"destination"];
  104. NSString * url = [outputOptions objectForKey:@"url"];
  105. NSString * access = [outputOptions objectForKey:@"access"];
  106. if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
  107. if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
  108. if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
  109. if( access ) [subOptions addObject:[NSString stringWithFormat:@"access=%@", access]];
  110. [optionsAsArray addObject:[NSString stringWithFormat:@"std{%@}", [subOptions componentsJoinedByString:@","]]];
  111. [subOptions removeAllObjects];
  112. }
  113. NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
  114. if( rtpOptions )
  115. {
  116. NSString * muxer = [rtpOptions objectForKey:@"muxer"];
  117. NSString * destination = [rtpOptions objectForKey:@"destination"];
  118. NSString * sdp = [rtpOptions objectForKey:@"sdp"];
  119. NSString * name = [rtpOptions objectForKey:@"name"];
  120. if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
  121. if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=%@", destination]];
  122. if( sdp ) [subOptions addObject:[NSString stringWithFormat:@"sdp=%@", sdp]];
  123. if( name ) [subOptions addObject:[NSString stringWithFormat:@"name=\"%@\"", name]];
  124. [optionsAsArray addObject:[NSString stringWithFormat:@"rtp{%@}", [subOptions componentsJoinedByString:@","]]];
  125. [subOptions removeAllObjects];
  126. }
  127. representedOptions = [optionsAsArray componentsJoinedByString:@":"];
  128. return representedOptions;
  129. }
  130. @end