作者ryanliang (暑假闲闲的大学生~~)
看板MacDev
标题[问题] 有关ObjC呼叫其他Class的Method及呼叫C Function的写法
时间Mon Nov 15 15:33:25 2010
各位板上先进,小弟在Method的呼叫上面出了很大的问题,但是我找不到为什
麽这样,所以我现在很头大,希望各位能够帮帮我。
这只程式跟上次问的画面问题是同一支(感谢zonble大),但现在问题在於,我
另外写了一个class,是在做格式的转换(RGB32 --> yv12),不过,我在呼叫
RGB32toI420这个method时,"感觉"并没有呼叫到它。
为什麽说感觉没有呢?因为我在另外一个class里面设了一个NSLog,要它一
进入就先印出"I'm in!",但它始终是没有印出来,
我的code大概是这样:
主程式呼叫的地方:
NSUInteger mLength = [mData length]; //设定mLength长度与mData一样
uint8_t *buffer = malloc(mLength - 54); //设定buffer格式及大小
[mData getBytes:buffer range:NSMakeRange(54, (mLength - 54))];
//将mData的资料copy到buffer且只存raw image的范围
if (mVideoGrabber == NULL)
{
NSLog(@"I'm in alloc!");
mVideoGrabber = [[VideoGrabber alloc] init];
}
NSData *i420Data = [[NSData alloc] initWithData:[mVideoGrabber
RGB32toI420:buffer length:(mLength - 54) width:640 height:480]];
NSLog(@"%i",[i420Data length]);//这边印出来的值永远都是0 不知道为什麽??
Class VideoGrabber的部份:
@implementation VideoGrabber
- (NSData *)RGB32toI420:(uint8_t *)data length:(NSUInteger)length width:
(NSUInteger)width_ height:(NSUInteger)height_
{
if (length != width_ * height_ * 4)
{
NSAssert(noErr == (length == (width_ * height_ * 4)),
@"Size Error !");
return nil;
}
else
{
NSLog(@"I'm in !"); /*这个"I'm in !"从来没有出现过,表示没呼
叫到这个method */
uint8_t *dataBlock = malloc((width_ * height_ * 4 / 2));
uint8_t *yPtr = dataBlock ;
uint8_t *uPtr = yPtr + width_ * height_;
uint8_t *vPtr = uPtr + (width_ / 2) * (height_ / 2);
/*image_input是一个Pure C的Function,它会做转换(不是我写的XD)
主要是它在计算的时候会把值回填到dataBlock中,所以function跑
完,dataBlock Array也跟着被填满了。*/
image_input(yPtr, uPtr, vPtr, width_, height_, width_,
data, width_ * 4, XVID_CSP_ABGR | XVID_CSP_VFLIP, 0);
/*这边return一个NAData主要是我想把转换玩的资料存在NSData中
所以我在写这个class的时後也是设定回传NSData*/
return [NSData dataWithBytes:dataBlock length:
(width_ * height_ * 4 /2)];
}
}
@end
以上就是这部份的程式,希望各位先进能够帮帮我~~
万分感激!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.219.177.46
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:35)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:36)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:37)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:41)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:43)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:46)
※ 编辑: ryanliang 来自: 61.219.177.46 (11/15 15:46)
1F:→ zonble:你先设 break point,然後用 single step 去看 11/15 15:48
2F:→ zonble:程式到底执行的路径是怎样 11/15 15:48
3F:→ ryanliang:了解 我现在马上做~~ 11/15 15:50
4F:→ ryanliang:我刚刚测试的结果 是size的问题 我预设是640*480 但是 11/15 16:29
5F:→ ryanliang:我测到的结果是1280*1024 真是见鬼了 内建iSight的解析 11/15 16:30
6F:→ ryanliang:度 只有640*480阿 怎麽出来这麽高的解析度的 怪怪@@ 11/15 16:31
7F:→ ryanliang:不过现在有测到确实有呼到RGB那个Method 但是里面的C函 11/15 16:32
8F:→ ryanliang:式 还是呼叫不到 跑到那就显示"EXC_BED_ACCESS" 不知道 11/15 16:34
9F:→ ryanliang:该怎麽呼才是对的C function呼叫方法 感谢教导~~ 11/15 16:36
10F:→ zonble:Bad Access 就是有指标指到非法的记忆体上,你先试试看 11/15 16:41
11F:→ zonble:找出到底出问题的是哪一个变数 11/15 16:41
12F:→ ryanliang:看不太出来哪一个参数不合理 dataBlock yPtr uPtr vPtr 11/15 17:52
13F:→ ryanliang:指标的时都正确 width_ heigh_ 也都正确 Flag的设定也 11/15 17:54
14F:→ ryanliang:确 唯一剩下data 不过我用sizeof去查大小 它永远显示8 11/15 17:55
15F:→ ryanliang:我想应该是它占8个byte 确切大小要用什麽指令可以查到? 11/15 17:57