NTESGLView.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // NTESGLView.m
  3. // NIM
  4. //
  5. // Created by fenric on 16/8/30.
  6. // Copyright © 2016年 Netease. All rights reserved.
  7. //
  8. #import "NTESGLView.h"
  9. @interface NTESGLView()
  10. {
  11. SDL_VoutOverlay _overlay;
  12. Uint16 _pitches[3];
  13. Uint8 *_pixels[3];
  14. }
  15. @end
  16. @implementation NTESGLView
  17. - (id) initWithFrame:(CGRect)frame
  18. {
  19. if (self = [super initWithFrame:frame]) {
  20. _overlay.format = SDL_FCC_I420;
  21. _overlay.planes = 3;
  22. _overlay.pitches = _pitches;
  23. _overlay.pixels = _pixels;
  24. _overlay.is_private = 0;
  25. _overlay.sar_num = 0;
  26. _overlay.sar_den = 0;
  27. }
  28. return self;
  29. }
  30. - (void) render: (NSData *)yuvData
  31. width:(NSUInteger)width
  32. height:(NSUInteger)height
  33. {
  34. if (yuvData) {
  35. _overlay.w = (int)width;
  36. _overlay.h = (int)height;
  37. _pitches[0] = width;
  38. _pitches[1] = _pitches[2] = _pitches[0] / 2;
  39. _pixels[0] = (UInt8 *)[yuvData bytes];
  40. _pixels[1] = _pixels[0] + width * height;
  41. _pixels[2] = _pixels[0] + width * height * 5 / 4;
  42. [self display:&_overlay clear:NO];
  43. }
  44. else {
  45. [self display:NULL clear:YES];
  46. }
  47. }
  48. @end